ported oc_db

This commit is contained in:
Frank Karlitschek 2012-05-03 13:06:08 +02:00
parent f85d076a4e
commit 97a8af7f25
29 changed files with 262 additions and 170 deletions

View File

@ -35,7 +35,7 @@ $params=array(
OCP\USER::getUser() OCP\USER::getUser()
); );
$query = OC_DB::prepare(" $query = OCP\DB::prepare("
SELECT id FROM *PREFIX*bookmarks SELECT id FROM *PREFIX*bookmarks
WHERE url LIKE ? WHERE url LIKE ?
AND user_id = ? AND user_id = ?
@ -43,7 +43,7 @@ $query = OC_DB::prepare("
$id = $query->execute($params)->fetchOne(); $id = $query->execute($params)->fetchOne();
$query = OC_DB::prepare(" $query = OCP\DB::prepare("
DELETE FROM *PREFIX*bookmarks DELETE FROM *PREFIX*bookmarks
WHERE id = $id WHERE id = $id
"); ");
@ -51,7 +51,7 @@ $query = OC_DB::prepare("
$result = $query->execute(); $result = $query->execute();
$query = OC_DB::prepare(" $query = OCP\DB::prepare("
DELETE FROM *PREFIX*bookmarks_tags DELETE FROM *PREFIX*bookmarks_tags
WHERE bookmark_id = $id WHERE bookmark_id = $id
"); ");

View File

@ -41,7 +41,7 @@ if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
$bookmark_id = (int)$_GET["id"]; $bookmark_id = (int)$_GET["id"];
$query = OC_DB::prepare(" $query = OCP\DB::prepare("
UPDATE *PREFIX*bookmarks UPDATE *PREFIX*bookmarks
SET url = ?, title =?, lastmodified = $_ut SET url = ?, title =?, lastmodified = $_ut
WHERE id = $bookmark_id WHERE id = $bookmark_id
@ -54,14 +54,14 @@ $params=array(
$query->execute($params); $query->execute($params);
# Remove old tags and insert new ones. # Remove old tags and insert new ones.
$query = OC_DB::prepare(" $query = OCP\DB::prepare("
DELETE FROM *PREFIX*bookmarks_tags DELETE FROM *PREFIX*bookmarks_tags
WHERE bookmark_id = $bookmark_id WHERE bookmark_id = $bookmark_id
"); ");
$query->execute(); $query->execute();
$query = OC_DB::prepare(" $query = OCP\DB::prepare("
INSERT INTO *PREFIX*bookmarks_tags INSERT INTO *PREFIX*bookmarks_tags
(bookmark_id, tag) (bookmark_id, tag)
VALUES (?, ?) VALUES (?, ?)

View File

@ -30,7 +30,7 @@ $RUNTIME_NOSETUPFS=true;
OCP\JSON::checkLoggedIn(); OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('bookmarks'); OCP\JSON::checkAppEnabled('bookmarks');
$query = OC_DB::prepare(" $query = OCP\DB::prepare("
UPDATE *PREFIX*bookmarks UPDATE *PREFIX*bookmarks
SET clickcount = clickcount + 1 SET clickcount = clickcount + 1
WHERE user_id = ? WHERE user_id = ?

6
apps/bookmarks/appinfo/migrate.php Normal file → Executable file
View File

@ -40,10 +40,10 @@ class OC_Migration_Provider_Bookmarks extends OC_Migration_Provider{
$idmap = array(); $idmap = array();
while( $row = $results->fetchRow() ){ while( $row = $results->fetchRow() ){
// Import each bookmark, saving its id into the map // Import each bookmark, saving its id into the map
$query = OC_DB::prepare( "INSERT INTO *PREFIX*bookmarks(url, title, user_id, public, added, lastmodified) VALUES (?, ?, ?, ?, ?, ?)" ); $query = OCP\DB::prepare( "INSERT INTO *PREFIX*bookmarks(url, title, user_id, public, added, lastmodified) VALUES (?, ?, ?, ?, ?, ?)" );
$query->execute( array( $row['url'], $row['title'], $this->uid, $row['public'], $row['added'], $row['lastmodified'] ) ); $query->execute( array( $row['url'], $row['title'], $this->uid, $row['public'], $row['added'], $row['lastmodified'] ) );
// Map the id // Map the id
$idmap[$row['id']] = OC_DB::insertid(); $idmap[$row['id']] = OCP\DB::insertid();
} }
// Now tags // Now tags
foreach($idmap as $oldid => $newid){ foreach($idmap as $oldid => $newid){
@ -51,7 +51,7 @@ class OC_Migration_Provider_Bookmarks extends OC_Migration_Provider{
$results = $query->execute( array( $oldid ) ); $results = $query->execute( array( $oldid ) );
while( $row = $results->fetchRow() ){ while( $row = $results->fetchRow() ){
// Import the tags for this bookmark, using the new bookmark id // Import the tags for this bookmark, using the new bookmark id
$query = OC_DB::prepare( "INSERT INTO *PREFIX*bookmarks_tags(bookmark_id, tag) VALUES (?, ?)" ); $query = OCP\DB::prepare( "INSERT INTO *PREFIX*bookmarks_tags(bookmark_id, tag) VALUES (?, ?)" );
$query->execute( array( $newid, $row['tag'] ) ); $query->execute( array( $newid, $row['tag'] ) );
} }
} }

View File

@ -82,7 +82,7 @@ function addBookmark($url, $title, $tags='') {
} }
//FIXME: Detect when user adds a known URL //FIXME: Detect when user adds a known URL
$query = OC_DB::prepare(" $query = OCP\DB::prepare("
INSERT INTO *PREFIX*bookmarks INSERT INTO *PREFIX*bookmarks
(url, title, user_id, public, added, lastmodified) (url, title, user_id, public, added, lastmodified)
VALUES (?, ?, ?, 0, $_ut, $_ut) VALUES (?, ?, ?, 0, $_ut, $_ut)
@ -105,10 +105,10 @@ function addBookmark($url, $title, $tags='') {
); );
$query->execute($params); $query->execute($params);
$b_id = OC_DB::insertid('*PREFIX*bookmarks'); $b_id = OCP\DB::insertid('*PREFIX*bookmarks');
if($b_id !== false) { if($b_id !== false) {
$query = OC_DB::prepare(" $query = OCP\DB::prepare("
INSERT INTO *PREFIX*bookmarks_tags INSERT INTO *PREFIX*bookmarks_tags
(bookmark_id, tag) (bookmark_id, tag)
VALUES (?, ?) VALUES (?, ?)

View File

@ -70,7 +70,7 @@ class OC_Bookmarks_Bookmarks{
} }
if($CONFIG_DBTYPE == 'pgsql' ){ if($CONFIG_DBTYPE == 'pgsql' ){
$query = OC_DB::prepare(' $query = OCP\DB::prepare('
SELECT id, url, title, '.($filterTagOnly?'':'url || title ||').' array_to_string(array_agg(tag), \' \') as tags SELECT id, url, title, '.($filterTagOnly?'':'url || title ||').' array_to_string(array_agg(tag), \' \') as tags
FROM *PREFIX*bookmarks FROM *PREFIX*bookmarks
LEFT JOIN *PREFIX*bookmarks_tags ON *PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id LEFT JOIN *PREFIX*bookmarks_tags ON *PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id
@ -87,7 +87,7 @@ class OC_Bookmarks_Bookmarks{
else else
$concatFunction = 'Concat(Concat( url, title), '; $concatFunction = 'Concat(Concat( url, title), ';
$query = OC_DB::prepare(' $query = OCP\DB::prepare('
SELECT id, url, title, ' SELECT id, url, title, '
.($filterTagOnly?'':$concatFunction). .($filterTagOnly?'':$concatFunction).
'CASE WHEN *PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id 'CASE WHEN *PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id

View File

@ -2,7 +2,7 @@
$installedVersion=OCP\Config::getAppValue('calendar', 'installed_version'); $installedVersion=OCP\Config::getAppValue('calendar', 'installed_version');
if (version_compare($installedVersion, '0.2.1', '<')) { if (version_compare($installedVersion, '0.2.1', '<')) {
$stmt = OC_DB::prepare( 'SELECT id, calendarcolor FROM *PREFIX*calendar_calendars WHERE calendarcolor IS NOT NULL' ); $stmt = OCP\DB::prepare( 'SELECT id, calendarcolor FROM *PREFIX*calendar_calendars WHERE calendarcolor IS NOT NULL' );
$result = $stmt->execute(); $result = $stmt->execute();
while( $row = $result->fetchRow()) { while( $row = $result->fetchRow()) {
$id = $row['id']; $id = $row['id'];
@ -11,7 +11,7 @@ if (version_compare($installedVersion, '0.2.1', '<')) {
continue; continue;
} }
$color = '#' .$color; $color = '#' .$color;
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET calendarcolor=? WHERE id=?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET calendarcolor=? WHERE id=?' );
$r = $stmt->execute(array($color,$id)); $r = $stmt->execute(array($color,$id));
} }
} }

View File

@ -54,7 +54,7 @@ class OC_Calendar_Calendar{
$active_where = ' AND active = ?'; $active_where = ' AND active = ?';
$values[] = $active; $values[] = $active;
} }
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*calendar_calendars WHERE userid = ?' . $active_where ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*calendar_calendars WHERE userid = ?' . $active_where );
$result = $stmt->execute($values); $result = $stmt->execute($values);
$calendars = array(); $calendars = array();
@ -81,7 +81,7 @@ class OC_Calendar_Calendar{
* @return associative array * @return associative array
*/ */
public static function find($id){ public static function find($id){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*calendar_calendars WHERE id = ?' ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*calendar_calendars WHERE id = ?' );
$result = $stmt->execute(array($id)); $result = $stmt->execute(array($id));
return $result->fetchRow(); return $result->fetchRow();
@ -106,10 +106,10 @@ class OC_Calendar_Calendar{
$uri = self::createURI($name, $uris ); $uri = self::createURI($name, $uris );
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)' ); $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)' );
$result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components)); $result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components));
return OC_DB::insertid('*PREFIX*calendar_calendar'); return OCP\DB::insertid('*PREFIX*calendar_calendar');
} }
/** /**
@ -126,10 +126,10 @@ class OC_Calendar_Calendar{
public static function addCalendarFromDAVData($principaluri,$uri,$name,$components,$timezone,$order,$color){ public static function addCalendarFromDAVData($principaluri,$uri,$name,$components,$timezone,$order,$color){
$userid = self::extractUserID($principaluri); $userid = self::extractUserID($principaluri);
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)' ); $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)' );
$result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components)); $result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components));
return OC_DB::insertid('*PREFIX*calendar_calendars'); return OCP\DB::insertid('*PREFIX*calendar_calendars');
} }
/** /**
@ -155,7 +155,7 @@ class OC_Calendar_Calendar{
if(is_null($order)) $order = $calendar['calendarorder']; if(is_null($order)) $order = $calendar['calendarorder'];
if(is_null($color)) $color = $calendar['calendarcolor']; if(is_null($color)) $color = $calendar['calendarcolor'];
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET displayname=?,calendarorder=?,calendarcolor=?,timezone=?,components=?,ctag=ctag+1 WHERE id=?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET displayname=?,calendarorder=?,calendarcolor=?,timezone=?,components=?,ctag=ctag+1 WHERE id=?' );
$result = $stmt->execute(array($name,$order,$color,$timezone,$components,$id)); $result = $stmt->execute(array($name,$order,$color,$timezone,$components,$id));
return true; return true;
@ -168,7 +168,7 @@ class OC_Calendar_Calendar{
* @return boolean * @return boolean
*/ */
public static function setCalendarActive($id,$active){ public static function setCalendarActive($id,$active){
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET active = ? WHERE id = ?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET active = ? WHERE id = ?' );
$stmt->execute(array($active, $id)); $stmt->execute(array($active, $id));
return true; return true;
@ -180,7 +180,7 @@ class OC_Calendar_Calendar{
* @return boolean * @return boolean
*/ */
public static function touchCalendar($id){ public static function touchCalendar($id){
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET ctag = ctag + 1 WHERE id = ?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET ctag = ctag + 1 WHERE id = ?' );
$stmt->execute(array($id)); $stmt->execute(array($id));
return true; return true;
@ -192,10 +192,10 @@ class OC_Calendar_Calendar{
* @return boolean * @return boolean
*/ */
public static function deleteCalendar($id){ public static function deleteCalendar($id){
$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*calendar_calendars WHERE id = ?' ); $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*calendar_calendars WHERE id = ?' );
$stmt->execute(array($id)); $stmt->execute(array($id));
$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE calendarid = ?' ); $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE calendarid = ?' );
$stmt->execute(array($id)); $stmt->execute(array($id));
return true; return true;

View File

@ -19,7 +19,7 @@ class OC_Calendar_Object{
* ['calendardata'] * ['calendardata']
*/ */
public static function all($id){ public static function all($id){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*calendar_objects WHERE calendarid = ?' ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*calendar_objects WHERE calendarid = ?' );
$result = $stmt->execute(array($id)); $result = $stmt->execute(array($id));
$calendarobjects = array(); $calendarobjects = array();
@ -41,7 +41,7 @@ class OC_Calendar_Object{
* in ['calendardata'] * in ['calendardata']
*/ */
public static function allInPeriod($id, $start, $end){ public static function allInPeriod($id, $start, $end){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*calendar_objects WHERE calendarid = ?' $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*calendar_objects WHERE calendarid = ?'
.' AND ((startdate >= ? AND startdate <= ? AND repeating = 0)' .' AND ((startdate >= ? AND startdate <= ? AND repeating = 0)'
.' OR (enddate >= ? AND enddate <= ? AND repeating = 0)' .' OR (enddate >= ? AND enddate <= ? AND repeating = 0)'
.' OR (startdate <= ? AND repeating = 1))' ); .' OR (startdate <= ? AND repeating = 1))' );
@ -66,7 +66,7 @@ class OC_Calendar_Object{
* @return associative array * @return associative array
*/ */
public static function find($id){ public static function find($id){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*calendar_objects WHERE id = ?' ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*calendar_objects WHERE id = ?' );
$result = $stmt->execute(array($id)); $result = $stmt->execute(array($id));
return $result->fetchRow(); return $result->fetchRow();
@ -79,7 +79,7 @@ class OC_Calendar_Object{
* @return associative array * @return associative array
*/ */
public static function findWhereDAVDataIs($cid,$uri){ public static function findWhereDAVDataIs($cid,$uri){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*calendar_objects WHERE calendarid = ? AND uri = ?' ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*calendar_objects WHERE calendarid = ? AND uri = ?' );
$result = $stmt->execute(array($cid,$uri)); $result = $stmt->execute(array($cid,$uri));
return $result->fetchRow(); return $result->fetchRow();
@ -103,12 +103,12 @@ class OC_Calendar_Object{
$uri = 'owncloud-'.md5($data.rand().time()).'.ics'; $uri = 'owncloud-'.md5($data.rand().time()).'.ics';
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*calendar_objects (calendarid,objecttype,startdate,enddate,repeating,summary,calendardata,uri,lastmodified) VALUES(?,?,?,?,?,?,?,?,?)' ); $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*calendar_objects (calendarid,objecttype,startdate,enddate,repeating,summary,calendardata,uri,lastmodified) VALUES(?,?,?,?,?,?,?,?,?)' );
$stmt->execute(array($id,$type,$startdate,$enddate,$repeating,$summary,$data,$uri,time())); $stmt->execute(array($id,$type,$startdate,$enddate,$repeating,$summary,$data,$uri,time()));
OC_Calendar_Calendar::touchCalendar($id); OC_Calendar_Calendar::touchCalendar($id);
return OC_DB::insertid('*PREFIX*calendar_objects'); return OCP\DB::insertid('*PREFIX*calendar_objects');
} }
/** /**
@ -122,12 +122,12 @@ class OC_Calendar_Object{
$object = OC_VObject::parse($data); $object = OC_VObject::parse($data);
list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*calendar_objects (calendarid,objecttype,startdate,enddate,repeating,summary,calendardata,uri,lastmodified) VALUES(?,?,?,?,?,?,?,?,?)' ); $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*calendar_objects (calendarid,objecttype,startdate,enddate,repeating,summary,calendardata,uri,lastmodified) VALUES(?,?,?,?,?,?,?,?,?)' );
$stmt->execute(array($id,$type,$startdate,$enddate,$repeating,$summary,$data,$uri,time())); $stmt->execute(array($id,$type,$startdate,$enddate,$repeating,$summary,$data,$uri,time()));
OC_Calendar_Calendar::touchCalendar($id); OC_Calendar_Calendar::touchCalendar($id);
return OC_DB::insertid('*PREFIX*calendar_objects'); return OCP\DB::insertid('*PREFIX*calendar_objects');
} }
/** /**
@ -143,7 +143,7 @@ class OC_Calendar_Object{
OC_Calendar_App::loadCategoriesFromVCalendar($object); OC_Calendar_App::loadCategoriesFromVCalendar($object);
list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' );
$stmt->execute(array($type,$startdate,$enddate,$repeating,$summary,$data,time(),$id)); $stmt->execute(array($type,$startdate,$enddate,$repeating,$summary,$data,time(),$id));
OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']); OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']);
@ -164,7 +164,7 @@ class OC_Calendar_Object{
$object = OC_VObject::parse($data); $object = OC_VObject::parse($data);
list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' );
$stmt->execute(array($type,$startdate,$enddate,$repeating,$summary,$data,time(),$oldobject['id'])); $stmt->execute(array($type,$startdate,$enddate,$repeating,$summary,$data,time(),$oldobject['id']));
OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']); OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']);
@ -179,7 +179,7 @@ class OC_Calendar_Object{
*/ */
public static function delete($id){ public static function delete($id){
$oldobject = self::find($id); $oldobject = self::find($id);
$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE id = ?' ); $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE id = ?' );
$stmt->execute(array($id)); $stmt->execute(array($id));
OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']); OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']);
@ -193,7 +193,7 @@ class OC_Calendar_Object{
* @return boolean * @return boolean
*/ */
public static function deleteFromDAVData($cid,$uri){ public static function deleteFromDAVData($cid,$uri){
$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE calendarid = ? AND uri=?' ); $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE calendarid = ? AND uri=?' );
$stmt->execute(array($cid,$uri)); $stmt->execute(array($cid,$uri));
OC_Calendar_Calendar::touchCalendar($cid); OC_Calendar_Calendar::touchCalendar($cid);
@ -201,7 +201,7 @@ class OC_Calendar_Object{
} }
public static function moveToCalendar($id, $calendarid){ public static function moveToCalendar($id, $calendarid){
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET calendarid=? WHERE id = ?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*calendar_objects SET calendarid=? WHERE id = ?' );
$stmt->execute(array($calendarid,$id)); $stmt->execute(array($calendarid,$id));
OC_Calendar_Calendar::touchCalendar($id); OC_Calendar_Calendar::touchCalendar($id);

22
apps/calendar/lib/share.php Normal file → Executable file
View File

@ -25,7 +25,7 @@ class OC_Calendar_Share{
}else{ }else{
$active_where = ''; $active_where = '';
} }
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE ((share = ? AND sharetype = "user") ' . $group_where . ') AND owner <> ? ' . $permission_where . ' ' . $active_where); $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE ((share = ? AND sharetype = "user") ' . $group_where . ') AND owner <> ? ' . $permission_where . ' ' . $active_where);
$result = $stmt->execute(array($userid, $userid)); $result = $stmt->execute(array($userid, $userid));
$return = array(); $return = array();
while( $row = $result->fetchRow()){ while( $row = $result->fetchRow()){
@ -40,7 +40,7 @@ class OC_Calendar_Share{
* @return: (array) $users - information about users a calendar / event is shared with * @return: (array) $users - information about users a calendar / event is shared with
*/ */
public static function allUsersSharedwith($id, $type){ public static function allUsersSharedwith($id, $type){
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE ' . $type . 'id = ? ORDER BY share'); $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE ' . $type . 'id = ? ORDER BY share');
$result = $stmt->execute(array($id)); $result = $stmt->execute(array($id));
$users = array(); $users = array();
while( $row = $result->fetchRow()){ while( $row = $result->fetchRow()){
@ -72,7 +72,7 @@ class OC_Calendar_Share{
if($sharetype == 'public'){ if($sharetype == 'public'){
$share = self::generate_token($id, $type); $share = self::generate_token($id, $type);
} }
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*calendar_share_' . $type . ' (owner,share,sharetype,' . $type . 'id,permissions' . (($type == self::CALENDAR)?', active':'') . ') VALUES(?,?,?,?,0' . (($type == self::CALENDAR)?', 1':'') . ')' ); $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*calendar_share_' . $type . ' (owner,share,sharetype,' . $type . 'id,permissions' . (($type == self::CALENDAR)?', active':'') . ') VALUES(?,?,?,?,0' . (($type == self::CALENDAR)?', 1':'') . ')' );
$result = $stmt->execute(array($owner,$share,$sharetype,$id)); $result = $stmt->execute(array($owner,$share,$sharetype,$id));
if($sharetype == 'public'){ if($sharetype == 'public'){
return $share; return $share;
@ -90,7 +90,7 @@ class OC_Calendar_Share{
* @return (bool) * @return (bool)
*/ */
public static function unshare($owner, $share, $sharetype, $id, $type){ public static function unshare($owner, $share, $sharetype, $id, $type){
$stmt = OC_DB::prepare('DELETE FROM *PREFIX*calendar_share_' . $type . ' WHERE owner = ? ' . (($sharetype != 'public')?'AND share = ?':'') . ' AND sharetype = ? AND ' . $type . 'id = ?'); $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*calendar_share_' . $type . ' WHERE owner = ? ' . (($sharetype != 'public')?'AND share = ?':'') . ' AND sharetype = ? AND ' . $type . 'id = ?');
if($sharetype != 'public'){ if($sharetype != 'public'){
$stmt->execute(array($owner,$share,$sharetype,$id)); $stmt->execute(array($owner,$share,$sharetype,$id));
}else{ }else{
@ -111,7 +111,7 @@ class OC_Calendar_Share{
if($sharetype == 'public' && $permission == 1){ if($sharetype == 'public' && $permission == 1){
$permission = 0; $permission = 0;
} }
$stmt = OC_DB::prepare('UPDATE *PREFIX*calendar_share_' . $type . ' SET permissions = ? WHERE share = ? AND sharetype = ? AND ' . $type . 'id = ?'); $stmt = OCP\DB::prepare('UPDATE *PREFIX*calendar_share_' . $type . ' SET permissions = ? WHERE share = ? AND sharetype = ? AND ' . $type . 'id = ?');
$stmt->execute(array($permission, $share, $sharetype, $id)); $stmt->execute(array($permission, $share, $sharetype, $id));
return true; return true;
} }
@ -148,7 +148,7 @@ class OC_Calendar_Share{
* @return (bool) * @return (bool)
*/ */
public static function is_already_shared($owner, $share, $sharetype, $id, $type){ public static function is_already_shared($owner, $share, $sharetype, $id, $type){
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE owner = ? AND share = ? AND sharetype = ? AND ' . $type . 'id = ?'); $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE owner = ? AND share = ? AND sharetype = ? AND ' . $type . 'id = ?');
$result = $stmt->execute(array($owner, $share, $sharetype, $id)); $result = $stmt->execute(array($owner, $share, $sharetype, $id));
if($result->numRows() > 0){ if($result->numRows() > 0){
return true; return true;
@ -191,7 +191,7 @@ class OC_Calendar_Share{
public static function is_editing_allowed($share, $id, $type){ public static function is_editing_allowed($share, $id, $type){
$group_where = self::group_sql(OC_Group::getUserGroups($share)); $group_where = self::group_sql(OC_Group::getUserGroups($share));
$permission_where = self::permission_sql('rw'); $permission_where = self::permission_sql('rw');
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE ((share = ? AND sharetype = "user") ' . $group_where . ') ' . $permission_where); $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE ((share = ? AND sharetype = "user") ' . $group_where . ') ' . $permission_where);
$result = $stmt->execute(array($share)); $result = $stmt->execute(array($share));
if($result->numRows() == 1){ if($result->numRows() == 1){
return true; return true;
@ -211,7 +211,7 @@ class OC_Calendar_Share{
*/ */
public static function check_access($share, $id, $type){ public static function check_access($share, $id, $type){
$group_where = self::group_sql(OC_Group::getUserGroups($share)); $group_where = self::group_sql(OC_Group::getUserGroups($share));
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE (' . $type . 'id = ? AND (share = ? AND sharetype = "user") ' . $group_where . ')'); $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE (' . $type . 'id = ? AND (share = ? AND sharetype = "user") ' . $group_where . ')');
$result = $stmt->execute(array($id,$share)); $result = $stmt->execute(array($id,$share));
$rows = $result->numRows(); $rows = $result->numRows();
if($rows > 0){ if($rows > 0){
@ -229,9 +229,9 @@ class OC_Calendar_Share{
* @return: mixed - bool if false, array with type and id if true * @return: mixed - bool if false, array with type and id if true
*/ */
public static function getElementByToken($token){ public static function getElementByToken($token){
$stmt_calendar = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . OC_Calendar_Share::CALENDAR . ' WHERE sharetype = "public" AND share = ?'); $stmt_calendar = OCP\DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . OC_Calendar_Share::CALENDAR . ' WHERE sharetype = "public" AND share = ?');
$result_calendar = $stmt_calendar->execute(array($token)); $result_calendar = $stmt_calendar->execute(array($token));
$stmt_event = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . OC_Calendar_Share::EVENT . ' WHERE sharetype = "public" AND share = ?'); $stmt_event = OCP\DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . OC_Calendar_Share::EVENT . ' WHERE sharetype = "public" AND share = ?');
$result_event = $stmt_event->execute(array($token)); $result_event = $stmt_event->execute(array($token));
$return = array(); $return = array();
if($result_calendar->numRows() == 0 && $result_event->numRows() == 0){ if($result_calendar->numRows() == 0 && $result_event->numRows() == 0){
@ -253,7 +253,7 @@ class OC_Calendar_Share{
* @param (string) $ * @param (string) $
*/ */
public static function set_active($share, $id, $active){ public static function set_active($share, $id, $active){
$stmt = OC_DB::prepare('UPDATE *PREFIX*calendar_share_calendar SET active = ? WHERE share = ? AND sharetype = "user" AND calendarid = ?'); $stmt = OCP\DB::prepare('UPDATE *PREFIX*calendar_share_calendar SET active = ? WHERE share = ? AND sharetype = "user" AND calendarid = ?');
$stmt->execute(array($active, $share, $id)); $stmt->execute(array($active, $share, $id));
} }
} }

6
apps/contacts/appinfo/migrate.php Normal file → Executable file
View File

@ -40,10 +40,10 @@ class OC_Migration_Provider_Contacts extends OC_Migration_Provider{
$idmap = array(); $idmap = array();
while( $row = $results->fetchRow() ){ while( $row = $results->fetchRow() ){
// Import each bookmark, saving its id into the map // Import each bookmark, saving its id into the map
$query = OC_DB::prepare( "INSERT INTO *PREFIX*contacts_addressbooks (`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)" ); $query = OCP\DB::prepare( "INSERT INTO *PREFIX*contacts_addressbooks (`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)" );
$query->execute( array( $this->uid, $row['displayname'], $row['uri'], $row['description'], $row['ctag'] ) ); $query->execute( array( $this->uid, $row['displayname'], $row['uri'], $row['description'], $row['ctag'] ) );
// Map the id // Map the id
$idmap[$row['id']] = OC_DB::insertid(); $idmap[$row['id']] = OCP\DB::insertid();
} }
// Now tags // Now tags
foreach($idmap as $oldid => $newid){ foreach($idmap as $oldid => $newid){
@ -51,7 +51,7 @@ class OC_Migration_Provider_Contacts extends OC_Migration_Provider{
$results = $query->execute( array( $oldid ) ); $results = $query->execute( array( $oldid ) );
while( $row = $results->fetchRow() ){ while( $row = $results->fetchRow() ){
// Import the tags for this bookmark, using the new bookmark id // Import the tags for this bookmark, using the new bookmark id
$query = OC_DB::prepare( "INSERT INTO *PREFIX*contacts_cards (`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)" ); $query = OCP\DB::prepare( "INSERT INTO *PREFIX*contacts_cards (`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)" );
$query->execute( array( $newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified'] ) ); $query->execute( array( $newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified'] ) );
} }
} }

View File

@ -44,7 +44,7 @@ class OC_Contacts_Addressbook{
* @return array * @return array
*/ */
public static function all($uid){ public static function all($uid){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE userid = ? ORDER BY displayname' ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE userid = ? ORDER BY displayname' );
$result = $stmt->execute(array($uid)); $result = $stmt->execute(array($uid));
$addressbooks = array(); $addressbooks = array();
@ -71,7 +71,7 @@ class OC_Contacts_Addressbook{
* @return associative array * @return associative array
*/ */
public static function find($id){ public static function find($id){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ?' ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
$result = $stmt->execute(array($id)); $result = $stmt->execute(array($id));
return $result->fetchRow(); return $result->fetchRow();
@ -93,10 +93,10 @@ class OC_Contacts_Addressbook{
$uri = self::createURI($name, $uris ); $uri = self::createURI($name, $uris );
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' ); $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' );
$result = $stmt->execute(array($userid,$name,$uri,$description,1)); $result = $stmt->execute(array($userid,$name,$uri,$description,1));
return OC_DB::insertid('*PREFIX*contacts_addressbooks'); return OCP\DB::insertid('*PREFIX*contacts_addressbooks');
} }
/** /**
@ -110,10 +110,10 @@ class OC_Contacts_Addressbook{
public static function addFromDAVData($principaluri,$uri,$name,$description){ public static function addFromDAVData($principaluri,$uri,$name,$description){
$userid = self::extractUserID($principaluri); $userid = self::extractUserID($principaluri);
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' ); $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' );
$result = $stmt->execute(array($userid,$name,$uri,$description,1)); $result = $stmt->execute(array($userid,$name,$uri,$description,1));
return OC_DB::insertid('*PREFIX*contacts_addressbooks'); return OCP\DB::insertid('*PREFIX*contacts_addressbooks');
} }
/** /**
@ -134,7 +134,7 @@ class OC_Contacts_Addressbook{
$description = $addressbook['description']; $description = $addressbook['description'];
} }
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET displayname=?,description=?, ctag=ctag+1 WHERE id=?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET displayname=?,description=?, ctag=ctag+1 WHERE id=?' );
$result = $stmt->execute(array($name,$description,$id)); $result = $stmt->execute(array($name,$description,$id));
return true; return true;
@ -192,7 +192,7 @@ class OC_Contacts_Addressbook{
$ids_sql = join(',', array_fill(0, count($active), '?')); $ids_sql = join(',', array_fill(0, count($active), '?'));
$prep = 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id IN ('.$ids_sql.') ORDER BY displayname'; $prep = 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id IN ('.$ids_sql.') ORDER BY displayname';
try { try {
$stmt = OC_DB::prepare( $prep ); $stmt = OCP\DB::prepare( $prep );
$result = $stmt->execute($active); $result = $stmt->execute($active);
} catch(Exception $e) { } catch(Exception $e) {
OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:active:, exception: '.$e->getMessage(),OCP\Util::DEBUG); OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:active:, exception: '.$e->getMessage(),OCP\Util::DEBUG);
@ -258,7 +258,7 @@ class OC_Contacts_Addressbook{
public static function delete($id){ public static function delete($id){
// FIXME: There's no error checking at all. // FIXME: There's no error checking at all.
self::setActive($id, false); self::setActive($id, false);
$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' ); $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
$stmt->execute(array($id)); $stmt->execute(array($id));
$cards = OC_Contacts_VCard::all($id); $cards = OC_Contacts_VCard::all($id);
@ -275,7 +275,7 @@ class OC_Contacts_Addressbook{
* @return boolean * @return boolean
*/ */
public static function touch($id){ public static function touch($id){
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET ctag = ctag + 1 WHERE id = ?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET ctag = ctag + 1 WHERE id = ?' );
$stmt->execute(array($id)); $stmt->execute(array($id));
return true; return true;

View File

@ -53,7 +53,7 @@ class OC_Contacts_VCard{
$id_sql = join(',', array_fill(0, count($id), '?')); $id_sql = join(',', array_fill(0, count($id), '?'));
$prep = 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid IN ('.$id_sql.') ORDER BY fullname'; $prep = 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid IN ('.$id_sql.') ORDER BY fullname';
try { try {
$stmt = OC_DB::prepare( $prep ); $stmt = OCP\DB::prepare( $prep );
$result = $stmt->execute($id); $result = $stmt->execute($id);
} catch(Exception $e) { } catch(Exception $e) {
OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::DEBUG); OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::DEBUG);
@ -62,7 +62,7 @@ class OC_Contacts_VCard{
} }
} elseif($id) { } elseif($id) {
try { try {
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? ORDER BY fullname' ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? ORDER BY fullname' );
$result = $stmt->execute(array($id)); $result = $stmt->execute(array($id));
} catch(Exception $e) { } catch(Exception $e) {
OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::DEBUG); OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::DEBUG);
@ -85,7 +85,7 @@ class OC_Contacts_VCard{
* @return associative array * @return associative array
*/ */
public static function find($id){ public static function find($id){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE id = ?' ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE id = ?' );
$result = $stmt->execute(array($id)); $result = $stmt->execute(array($id));
return $result->fetchRow(); return $result->fetchRow();
@ -98,7 +98,7 @@ class OC_Contacts_VCard{
* @return associative array * @return associative array
*/ */
public static function findWhereDAVDataIs($aid,$uri){ public static function findWhereDAVDataIs($aid,$uri){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri = ?' ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri = ?' );
$result = $stmt->execute(array($aid,$uri)); $result = $stmt->execute(array($aid,$uri));
return $result->fetchRow(); return $result->fetchRow();
@ -147,7 +147,7 @@ class OC_Contacts_VCard{
* @returns true if the UID has been changed. * @returns true if the UID has been changed.
*/ */
protected static function trueUID($aid, &$uid) { protected static function trueUID($aid, &$uid) {
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri = ?' ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri = ?' );
$uri = $uid.'.vcf'; $uri = $uid.'.vcf';
$result = $stmt->execute(array($aid,$uri)); $result = $stmt->execute(array($aid,$uri));
if($result->numRows() > 0){ if($result->numRows() > 0){
@ -282,9 +282,9 @@ class OC_Contacts_VCard{
} }
$data = $card->serialize(); $data = $card->serialize();
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' ); $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' );
$result = $stmt->execute(array($aid,$fn,$data,$uri,time())); $result = $stmt->execute(array($aid,$fn,$data,$uri,time()));
$newid = OC_DB::insertid('*PREFIX*contacts_cards'); $newid = OCP\DB::insertid('*PREFIX*contacts_cards');
OC_Contacts_Addressbook::touch($aid); OC_Contacts_Addressbook::touch($aid);
@ -308,7 +308,7 @@ class OC_Contacts_VCard{
* @param array $objects An array of [id, carddata]. * @param array $objects An array of [id, carddata].
*/ */
public static function updateDataByID($objects){ public static function updateDataByID($objects){
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET carddata = ?, lastmodified = ? WHERE id = ?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET carddata = ?, lastmodified = ? WHERE id = ?' );
$now = new DateTime; $now = new DateTime;
foreach($objects as $object) { foreach($objects as $object) {
$vcard = OC_VObject::parse($object[1]); $vcard = OC_VObject::parse($object[1]);
@ -350,7 +350,7 @@ class OC_Contacts_VCard{
$card->setString('REV', $now->format(DateTime::W3C)); $card->setString('REV', $now->format(DateTime::W3C));
$data = $card->serialize(); $data = $card->serialize();
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?' );
$result = $stmt->execute(array($fn,$data,time(),$id)); $result = $stmt->execute(array($fn,$data,time(),$id));
OC_Contacts_Addressbook::touch($oldcard['addressbookid']); OC_Contacts_Addressbook::touch($oldcard['addressbookid']);
@ -378,7 +378,7 @@ class OC_Contacts_VCard{
*/ */
public static function delete($id){ public static function delete($id){
// FIXME: Add error checking. // FIXME: Add error checking.
$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE id = ?' ); $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE id = ?' );
$stmt->execute(array($id)); $stmt->execute(array($id));
return true; return true;
@ -392,7 +392,7 @@ class OC_Contacts_VCard{
*/ */
public static function deleteFromDAVData($aid,$uri){ public static function deleteFromDAVData($aid,$uri){
// FIXME: Add error checking. Deleting a card gives an Kontact/Akonadi error. // FIXME: Add error checking. Deleting a card gives an Kontact/Akonadi error.
$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri=?' ); $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri=?' );
$stmt->execute(array($aid,$uri)); $stmt->execute(array($aid,$uri));
OC_Contacts_Addressbook::touch($aid); OC_Contacts_Addressbook::touch($aid);
@ -521,7 +521,7 @@ class OC_Contacts_VCard{
$id_sql = join(',', array_fill(0, count($id), '?')); $id_sql = join(',', array_fill(0, count($id), '?'));
$prep = 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id IN ('.$id_sql.')'; $prep = 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id IN ('.$id_sql.')';
try { try {
$stmt = OC_DB::prepare( $prep ); $stmt = OCP\DB::prepare( $prep );
//$aid = array($aid); //$aid = array($aid);
$vals = array_merge((array)$aid, $id); $vals = array_merge((array)$aid, $id);
$result = $stmt->execute($vals); $result = $stmt->execute($vals);
@ -533,7 +533,7 @@ class OC_Contacts_VCard{
} }
} else { } else {
try { try {
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?' ); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?' );
$result = $stmt->execute(array($aid, $id)); $result = $stmt->execute(array($aid, $id));
} catch(Exception $e) { } catch(Exception $e) {
OCP\Util::writeLog('contacts','OC_Contacts_VCard::moveToAddressBook:, exception: '.$e->getMessage(),OCP\Util::DEBUG); OCP\Util::writeLog('contacts','OC_Contacts_VCard::moveToAddressBook:, exception: '.$e->getMessage(),OCP\Util::DEBUG);

View File

@ -14,10 +14,10 @@ if(!$checkOnly){
//create the file cache if necesary //create the file cache if necesary
if($force or !OC_FileCache::inCache('')){ if($force or !OC_FileCache::inCache('')){
if(!$checkOnly){ if(!$checkOnly){
OC_DB::beginTransaction(); OCP\DB::beginTransaction();
OC_FileCache::scan($dir,$eventSource); OC_FileCache::scan($dir,$eventSource);
OC_FileCache::clean(); OC_FileCache::clean();
OC_DB::commit(); OCP\DB::commit();
$eventSource->send('success',true); $eventSource->send('success',true);
}else{ }else{
OCP\JSON::success(array('data'=>array('done'=>true))); OCP\JSON::success(array('data'=>array('done'=>true)));

View File

@ -40,7 +40,7 @@ class OC_Share {
*/ */
public function __construct($source, $uid_shared_with, $permissions) { public function __construct($source, $uid_shared_with, $permissions) {
$uid_owner = OCP\USER::getUser(); $uid_owner = OCP\USER::getUser();
$query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); $query = OCP\DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)");
if ($uid_shared_with == self::PUBLICLINK) { if ($uid_shared_with == self::PUBLICLINK) {
$token = sha1("$uid_shared_with-$source"); $token = sha1("$uid_shared_with-$source");
$query->execute(array($uid_owner, self::PUBLICLINK, $source, $token, $permissions)); $query->execute(array($uid_owner, self::PUBLICLINK, $source, $token, $permissions));
@ -69,7 +69,7 @@ class OC_Share {
} }
foreach ($uid_shared_with as $uid) { foreach ($uid_shared_with as $uid) {
// Check if this item is already shared with the user // Check if this item is already shared with the user
$checkSource = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with ".self::getUsersAndGroups($uid)); $checkSource = OCP\DB::prepare("SELECT source FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with ".self::getUsersAndGroups($uid));
$resultCheckSource = $checkSource->execute(array($source))->fetchAll(); $resultCheckSource = $checkSource->execute(array($source))->fetchAll();
// TODO Check if the source is inside a folder // TODO Check if the source is inside a folder
if (count($resultCheckSource) > 0 && !isset($gid)) { if (count($resultCheckSource) > 0 && !isset($gid)) {
@ -101,11 +101,11 @@ class OC_Share {
// Add file to filesystem cache // Add file to filesystem cache
$userDirectory = "/".OCP\USER::getUser()."/files"; $userDirectory = "/".OCP\USER::getUser()."/files";
$data = OC_Filecache::get(substr($source, strlen($userDirectory))); $data = OC_Filecache::get(substr($source, strlen($userDirectory)));
$parentQuery = OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE path=?'); $parentQuery = OCP\DB::prepare('SELECT id FROM *PREFIX*fscache WHERE path=?');
$parentResult = $parentQuery->execute(array($sharedFolder))->fetchRow(); $parentResult = $parentQuery->execute(array($sharedFolder))->fetchRow();
$parent = $parentResult['id']; $parent = $parentResult['id'];
$is_writeable = $permissions & OC_Share::WRITE; $is_writeable = $permissions & OC_Share::WRITE;
$cacheQuery = OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart, user, writable) VALUES(?,?,?,?,?,?,?,?,?,?)'); $cacheQuery = OCP\DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart, user, writable) VALUES(?,?,?,?,?,?,?,?,?,?)');
$cacheQuery->execute(array($parent, basename($target), $target, $data['size'], $data['mtime'], $data['ctime'], $data['mimetype'], dirname($data['mimetype']), $uid, $is_writeable)); $cacheQuery->execute(array($parent, basename($target), $target, $data['size'], $data['mtime'], $data['ctime'], $data['mimetype'], dirname($data['mimetype']), $uid, $is_writeable));
} }
} }
@ -169,7 +169,7 @@ class OC_Share {
$folders = self::getParentFolders($oldTarget); $folders = self::getParentFolders($oldTarget);
$source = $folders['source'].substr($oldTarget, strlen($folders['target'])); $source = $folders['source'].substr($oldTarget, strlen($folders['target']));
$item = self::getItem($folders['target']); $item = self::getItem($folders['target']);
$query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); $query = OCP\DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)");
$query->execute(array($item[0]['uid_owner'], OCP\USER::getUser(), $source, $newTarget, $item[0]['permissions'])); $query->execute(array($item[0]['uid_owner'], OCP\USER::getUser(), $source, $newTarget, $item[0]['permissions']));
} }
@ -180,7 +180,7 @@ class OC_Share {
*/ */
public static function getItem($target) { public static function getItem($target) {
$target = self::cleanPath($target); $target = self::cleanPath($target);
$query = OC_DB::prepare("SELECT uid_owner, source, permissions FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); $query = OCP\DB::prepare("SELECT uid_owner, source, permissions FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1");
return $query->execute(array($target, OCP\USER::getUser()))->fetchAll(); return $query->execute(array($target, OCP\USER::getUser()))->fetchAll();
} }
@ -191,7 +191,7 @@ class OC_Share {
*/ */
public static function getMySharedItem($source) { public static function getMySharedItem($source) {
$source = self::cleanPath($source); $source = self::cleanPath($source);
$query = OC_DB::prepare("SELECT uid_shared_with, permissions FROM *PREFIX*sharing WHERE source = ? AND uid_owner = ?"); $query = OCP\DB::prepare("SELECT uid_shared_with, permissions FROM *PREFIX*sharing WHERE source = ? AND uid_owner = ?");
$result = $query->execute(array($source, OCP\USER::getUser()))->fetchAll(); $result = $query->execute(array($source, OCP\USER::getUser()))->fetchAll();
if (count($result) > 0) { if (count($result) > 0) {
return $result; return $result;
@ -207,7 +207,7 @@ class OC_Share {
* @return An array with all items the user is sharing * @return An array with all items the user is sharing
*/ */
public static function getMySharedItems() { public static function getMySharedItems() {
$query = OC_DB::prepare("SELECT uid_shared_with, source, permissions FROM *PREFIX*sharing WHERE uid_owner = ?"); $query = OCP\DB::prepare("SELECT uid_shared_with, source, permissions FROM *PREFIX*sharing WHERE uid_owner = ?");
return $query->execute(array(OCP\USER::getUser()))->fetchAll(); return $query->execute(array(OCP\USER::getUser()))->fetchAll();
} }
@ -226,7 +226,7 @@ class OC_Share {
$folder .= "/"; $folder .= "/";
} }
$length = strlen($folder); $length = strlen($folder);
$query = OC_DB::prepare("SELECT uid_owner, source, target, permissions FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups()); $query = OCP\DB::prepare("SELECT uid_owner, source, target, permissions FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups());
return $query->execute(array($length, $folder, $length, $folder))->fetchAll(); return $query->execute(array($length, $folder, $length, $folder))->fetchAll();
} }
@ -237,7 +237,7 @@ class OC_Share {
*/ */
public static function getParentFolders($target) { public static function getParentFolders($target) {
$target = self::cleanPath($target); $target = self::cleanPath($target);
$query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with".self::getUsersAndGroups()." LIMIT 1"); $query = OCP\DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with".self::getUsersAndGroups()." LIMIT 1");
// Prevent searching for user directory e.g. '/MTGap/files' // Prevent searching for user directory e.g. '/MTGap/files'
$userDirectory = substr($target, 0, strpos($target, "files") + 5); $userDirectory = substr($target, 0, strpos($target, "files") + 5);
$target = dirname($target); $target = dirname($target);
@ -265,7 +265,7 @@ class OC_Share {
*/ */
public static function getSource($target) { public static function getSource($target) {
$target = self::cleanPath($target); $target = self::cleanPath($target);
$query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with ".self::getUsersAndGroups()." LIMIT 1"); $query = OCP\DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with ".self::getUsersAndGroups()." LIMIT 1");
$result = $query->execute(array($target))->fetchAll(); $result = $query->execute(array($target))->fetchAll();
if (count($result) > 0) { if (count($result) > 0) {
return $result[0]['source']; return $result[0]['source'];
@ -281,7 +281,7 @@ class OC_Share {
public static function getTarget($source) { public static function getTarget($source) {
$source = self::cleanPath($source); $source = self::cleanPath($source);
$query = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE source = ? AND uid_owner = ? LIMIT 1"); $query = OCP\DB::prepare("SELECT target FROM *PREFIX*sharing WHERE source = ? AND uid_owner = ? LIMIT 1");
$result = $query->execute(array($source, OCP\USER::getUser()))->fetchAll(); $result = $query->execute(array($source, OCP\USER::getUser()))->fetchAll();
if (count($result) > 0) { if (count($result) > 0) {
return $result[0]['target']; return $result[0]['target'];
@ -298,7 +298,7 @@ class OC_Share {
*/ */
public static function getPermissions($target) { public static function getPermissions($target) {
$target = self::cleanPath($target); $target = self::cleanPath($target);
$query = OC_DB::prepare("SELECT permissions FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with ".self::getUsersAndGroups()." LIMIT 1"); $query = OCP\DB::prepare("SELECT permissions FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with ".self::getUsersAndGroups()." LIMIT 1");
$result = $query->execute(array($target))->fetchAll(); $result = $query->execute(array($target))->fetchAll();
if (count($result) > 0) { if (count($result) > 0) {
return $result[0]['permissions']; return $result[0]['permissions'];
@ -330,7 +330,7 @@ class OC_Share {
* @return The token of the public link, a sha1 hash * @return The token of the public link, a sha1 hash
*/ */
public static function getTokenFromSource($source) { public static function getTokenFromSource($source) {
$query = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? AND uid_owner = ? LIMIT 1"); $query = OCP\DB::prepare("SELECT target FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? AND uid_owner = ? LIMIT 1");
$result = $query->execute(array($source, self::PUBLICLINK, OCP\USER::getUser()))->fetchAll(); $result = $query->execute(array($source, self::PUBLICLINK, OCP\USER::getUser()))->fetchAll();
if (count($result) > 0) { if (count($result) > 0) {
return $result[0]['target']; return $result[0]['target'];
@ -350,7 +350,7 @@ class OC_Share {
public static function setTarget($oldTarget, $newTarget) { public static function setTarget($oldTarget, $newTarget) {
$oldTarget = self::cleanPath($oldTarget); $oldTarget = self::cleanPath($oldTarget);
$newTarget = self::cleanPath($newTarget); $newTarget = self::cleanPath($newTarget);
$query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = REPLACE(target, ?, ?) WHERE uid_shared_with ".self::getUsersAndGroups()); $query = OCP\DB::prepare("UPDATE *PREFIX*sharing SET target = REPLACE(target, ?, ?) WHERE uid_shared_with ".self::getUsersAndGroups());
$query->execute(array($oldTarget, $newTarget)); $query->execute(array($oldTarget, $newTarget));
} }
@ -365,7 +365,7 @@ class OC_Share {
*/ */
public static function setPermissions($source, $uid_shared_with, $permissions) { public static function setPermissions($source, $uid_shared_with, $permissions) {
$source = self::cleanPath($source); $source = self::cleanPath($source);
$query = OC_DB::prepare("UPDATE *PREFIX*sharing SET permissions = ? WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ? AND uid_shared_with ".self::getUsersAndGroups($uid_shared_with)); $query = OCP\DB::prepare("UPDATE *PREFIX*sharing SET permissions = ? WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ? AND uid_shared_with ".self::getUsersAndGroups($uid_shared_with));
$query->execute(array($permissions, strlen($source), $source, OCP\USER::getUser())); $query->execute(array($permissions, strlen($source), $source, OCP\USER::getUser()));
} }
@ -379,7 +379,7 @@ class OC_Share {
*/ */
public static function unshare($source, $uid_shared_with) { public static function unshare($source, $uid_shared_with) {
$source = self::cleanPath($source); $source = self::cleanPath($source);
$query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ? AND uid_shared_with ".self::getUsersAndGroups($uid_shared_with)); $query = OCP\DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ? AND uid_shared_with ".self::getUsersAndGroups($uid_shared_with));
$query->execute(array(strlen($source), $source, OCP\USER::getUser())); $query->execute(array(strlen($source), $source, OCP\USER::getUser()));
} }
@ -394,10 +394,10 @@ class OC_Share {
public static function unshareFromMySelf($target, $delete = true) { public static function unshareFromMySelf($target, $delete = true) {
$target = self::cleanPath($target); $target = self::cleanPath($target);
if ($delete) { if ($delete) {
$query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups()); $query = OCP\DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups());
$query->execute(array(strlen($target), $target)); $query->execute(array(strlen($target), $target));
} else { } else {
$query = OC_DB::prepare("UPDATE *PREFIX*sharing SET permissions = ? WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups()); $query = OCP\DB::prepare("UPDATE *PREFIX*sharing SET permissions = ? WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups());
$query->execute(array(self::UNSHARED, strlen($target), $target)); $query->execute(array(self::UNSHARED, strlen($target), $target));
} }
} }
@ -411,7 +411,7 @@ class OC_Share {
if ($target = self::getTarget($source)) { if ($target = self::getTarget($source)) {
// Forward hook to notify of changes to target file // Forward hook to notify of changes to target file
OC_Hook::emit("OC_Filesystem", "post_delete", array('path' => $target)); OC_Hook::emit("OC_Filesystem", "post_delete", array('path' => $target));
$query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ?"); $query = OCP\DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ?");
$query->execute(array(strlen($source), $source, OCP\USER::getUser())); $query->execute(array(strlen($source), $source, OCP\USER::getUser()));
} }
@ -424,7 +424,7 @@ class OC_Share {
public static function renameItem($arguments) { public static function renameItem($arguments) {
$oldSource = "/".OCP\USER::getUser()."/files".self::cleanPath($arguments['oldpath']); $oldSource = "/".OCP\USER::getUser()."/files".self::cleanPath($arguments['oldpath']);
$newSource = "/".OCP\USER::getUser()."/files".self::cleanPath($arguments['newpath']); $newSource = "/".OCP\USER::getUser()."/files".self::cleanPath($arguments['newpath']);
$query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); $query = OCP\DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?");
$query->execute(array($oldSource, $newSource, OCP\USER::getUser())); $query->execute(array($oldSource, $newSource, OCP\USER::getUser()));
} }
@ -437,17 +437,17 @@ class OC_Share {
} }
public static function removeUser($arguments) { public static function removeUser($arguments) {
$query = OC_DB::prepare('DELETE FROM *PREFIX*sharing WHERE uid_owner = ? OR uid_shared_with '.self::getUsersAndGroups($arguments['uid'])); $query = OCP\DB::prepare('DELETE FROM *PREFIX*sharing WHERE uid_owner = ? OR uid_shared_with '.self::getUsersAndGroups($arguments['uid']));
$query->execute(array($arguments['uid'])); $query->execute(array($arguments['uid']));
} }
public static function addToGroupShare($arguments) { public static function addToGroupShare($arguments) {
$length = -strlen($arguments['gid']) - 1; $length = -strlen($arguments['gid']) - 1;
$query = OC_DB::prepare('SELECT uid_owner, source, permissions FROM *PREFIX*sharing WHERE SUBSTR(uid_shared_with, '.$length.') = ?'); $query = OCP\DB::prepare('SELECT uid_owner, source, permissions FROM *PREFIX*sharing WHERE SUBSTR(uid_shared_with, '.$length.') = ?');
$gid = '@'.$arguments['gid']; $gid = '@'.$arguments['gid'];
$result = $query->execute(array($gid))->fetchAll(); $result = $query->execute(array($gid))->fetchAll();
if (count($result) > 0) { if (count($result) > 0) {
$query = OC_DB::prepare('INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)'); $query = OCP\DB::prepare('INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)');
$sharedFolder = '/'.$arguments['uid'].'/files/Shared/'; $sharedFolder = '/'.$arguments['uid'].'/files/Shared/';
$lastSource = ''; $lastSource = '';
for ($i = 0; $i < count($result) - 1; $i++) { for ($i = 0; $i < count($result) - 1; $i++) {
@ -460,7 +460,7 @@ class OC_Share {
} }
public static function removeFromGroupShare($arguments) { public static function removeFromGroupShare($arguments) {
$query = OC_DB::prepare('DELETE FROM *PREFIX*sharing WHERE uid_shared_with = ?'); $query = OCP\DB::prepare('DELETE FROM *PREFIX*sharing WHERE uid_shared_with = ?');
$query->execute(array($arguments['uid'].'@'.$arguments['gid'])); $query->execute(array($arguments['uid'].'@'.$arguments['gid']));
} }

View File

@ -227,7 +227,7 @@ class OC_Filestorage_Shared extends OC_Filestorage {
} }
if ($size > 0) { if ($size > 0) {
$dbpath = rtrim($this->datadir.$path, "/"); $dbpath = rtrim($this->datadir.$path, "/");
// $query = OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)"); // $query = OCP\DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
// $result = $query->execute(array($dbpath, $size)); // $result = $query->execute(array($dbpath, $size));
} }
} }
@ -241,7 +241,7 @@ class OC_Filestorage_Shared extends OC_Filestorage {
$path = dirname($path); $path = dirname($path);
} }
$dbpath = rtrim($this->datadir.$path, "/"); $dbpath = rtrim($this->datadir.$path, "/");
// $query = OC_DB::prepare("DELETE FROM *PREFIX*/*foldersize*/ WHERE path = ?"); // $query = OCP\DB::prepare("DELETE FROM *PREFIX*/*foldersize*/ WHERE path = ?");
// $result = $query->execute(array($dbpath)); // $result = $query->execute(array($dbpath));
if ($path != "/" && $path != "") { if ($path != "/" && $path != "") {
$parts = explode("/", $path); $parts = explode("/", $path);

View File

@ -48,13 +48,13 @@ function handleGetThumbnails($albumname) {
} }
function handleGalleryScanning() { function handleGalleryScanning() {
OC_DB::beginTransaction(); OCP\DB::beginTransaction();
set_time_limit(0); set_time_limit(0);
OC_Gallery_Album::cleanup(); OC_Gallery_Album::cleanup();
$eventSource = new OC_EventSource(); $eventSource = new OC_EventSource();
OC_Gallery_Scanner::scan($eventSource); OC_Gallery_Scanner::scan($eventSource);
$eventSource->close(); $eventSource->close();
OC_DB::commit(); OCP\DB::commit();
} }
function handleFilescan($cleanup) { function handleFilescan($cleanup) {

View File

@ -43,7 +43,7 @@ OCP\App::addNavigationEntry( array(
class OC_GallerySearchProvider extends OC_Search_Provider{ class OC_GallerySearchProvider extends OC_Search_Provider{
function search($query){ function search($query){
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ? AND album_name LIKE ?'); $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ? AND album_name LIKE ?');
$result = $stmt->execute(array(OCP\USER::getUser(),'%'.$query.'%')); $result = $stmt->execute(array(OCP\USER::getUser(),'%'.$query.'%'));
$results=array(); $results=array();
while($row=$result->fetchRow()){ while($row=$result->fetchRow()){

View File

@ -25,7 +25,7 @@ require_once('base.php');
class OC_Gallery_Album { class OC_Gallery_Album {
public static function create($owner, $name, $path){ public static function create($owner, $name, $path){
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (uid_owner, album_name, album_path, parent_path) VALUES (?, ?, ?, ?)'); $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*gallery_albums (uid_owner, album_name, album_path, parent_path) VALUES (?, ?, ?, ?)');
$stmt->execute(array($owner, $name, $path, self::getParentPath($path))); $stmt->execute(array($owner, $name, $path, self::getParentPath($path)));
} }
@ -56,7 +56,7 @@ class OC_Gallery_Album {
$sql .= ' AND parent_path LIKE ?'; $sql .= ' AND parent_path LIKE ?';
$args[] = $parent; $args[] = $parent;
} }
$stmt = OC_DB::prepare($sql); $stmt = OCP\DB::prepare($sql);
return $stmt->execute($args); return $stmt->execute($args);
} }
@ -82,12 +82,12 @@ class OC_Gallery_Album {
$order = OCP\Config::getUserValue($owner, 'gallery', 'order', 'ASC'); $order = OCP\Config::getUserValue($owner, 'gallery', 'order', 'ASC');
$sql .= ' ORDER BY album_name ' . $order; $sql .= ' ORDER BY album_name ' . $order;
$stmt = OC_DB::prepare($sql); $stmt = OCP\DB::prepare($sql);
return $stmt->execute($args); return $stmt->execute($args);
} }
public static function changePath($oldname, $newname, $owner) { public static function changePath($oldname, $newname, $owner) {
$stmt = OC_DB::prepare('UPDATE *PREFIX*gallery_albums SET album_path=? WHERE uid_owner=? AND album_path=?'); $stmt = OCP\DB::prepare('UPDATE *PREFIX*gallery_albums SET album_path=? WHERE uid_owner=? AND album_path=?');
$stmt->execute(array($newname, $owner, $oldname)); $stmt->execute(array($newname, $owner, $oldname));
} }
@ -99,7 +99,7 @@ class OC_Gallery_Album {
public static function getAlbumSize($id){ public static function getAlbumSize($id){
$sql = 'SELECT COUNT(*) as size FROM *PREFIX*gallery_photos WHERE album_id = ?'; $sql = 'SELECT COUNT(*) as size FROM *PREFIX*gallery_photos WHERE album_id = ?';
$stmt = OC_DB::prepare($sql); $stmt = OCP\DB::prepare($sql);
$result=$stmt->execute(array($id))->fetchRow(); $result=$stmt->execute(array($id))->fetchRow();
return $result['size']; return $result['size'];
} }
@ -107,7 +107,7 @@ class OC_Gallery_Album {
public static function getIntermediateGallerySize($path) { public static function getIntermediateGallerySize($path) {
$path .= '%'; $path .= '%';
$sql = 'SELECT COUNT(*) as size FROM *PREFIX*gallery_photos photos, *PREFIX*gallery_albums albums WHERE photos.album_id = albums.album_id AND uid_owner = ? AND file_path LIKE ?'; $sql = 'SELECT COUNT(*) as size FROM *PREFIX*gallery_photos photos, *PREFIX*gallery_albums albums WHERE photos.album_id = albums.album_id AND uid_owner = ? AND file_path LIKE ?';
$stmt = OC_DB::prepare($sql); $stmt = OCP\DB::prepare($sql);
$result = $stmt->execute(array(OCP\USER::getUser(), $path))->fetchRow(); $result = $stmt->execute(array(OCP\USER::getUser(), $path))->fetchRow();
return $result['size']; return $result['size'];
} }

View File

@ -23,7 +23,7 @@
class OC_Gallery_Photo { class OC_Gallery_Photo {
public static function create($albumId, $img){ public static function create($albumId, $img){
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)'); $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)');
$stmt->execute(array($albumId, $img)); $stmt->execute(array($albumId, $img));
} }
public static function find($albumId, $img=null){ public static function find($albumId, $img=null){
@ -33,11 +33,11 @@ class OC_Gallery_Photo {
$sql .= ' AND file_path = ?'; $sql .= ' AND file_path = ?';
$args[] = $img; $args[] = $img;
} }
$stmt = OC_DB::prepare($sql); $stmt = OCP\DB::prepare($sql);
return $stmt->execute($args); return $stmt->execute($args);
} }
public static function findForAlbum($owner, $album_name){ public static function findForAlbum($owner, $album_name){
$stmt = OC_DB::prepare('SELECT *' $stmt = OCP\DB::prepare('SELECT *'
.' FROM *PREFIX*gallery_photos photos,' .' FROM *PREFIX*gallery_photos photos,'
.' *PREFIX*gallery_albums albums' .' *PREFIX*gallery_albums albums'
.' WHERE albums.uid_owner = ?' .' WHERE albums.uid_owner = ?'
@ -47,22 +47,22 @@ class OC_Gallery_Photo {
} }
public static function removeByPath($path, $album_id) { public static function removeByPath($path, $album_id) {
$stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE file_path LIKE ? and album_id = ?'); $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE file_path LIKE ? and album_id = ?');
$stmt->execute(array($path, $album_id)); $stmt->execute(array($path, $album_id));
} }
public static function removeById($id) { public static function removeById($id) {
$stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE photo_id = ?'); $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE photo_id = ?');
$stmt->execute(array($id)); $stmt->execute(array($id));
} }
public static function removeByAlbumId($albumid) { public static function removeByAlbumId($albumid) {
$stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE album_id = ?'); $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE album_id = ?');
$stmt->execute(array($albumid)); $stmt->execute(array($albumid));
} }
public static function changePath($oldAlbumId, $newAlbumId, $oldpath, $newpath) { public static function changePath($oldAlbumId, $newAlbumId, $oldpath, $newpath) {
$stmt = OC_DB::prepare("UPDATE *PREFIX*gallery_photos SET file_path = ?, album_id = ? WHERE album_id = ? and file_path = ?"); $stmt = OCP\DB::prepare("UPDATE *PREFIX*gallery_photos SET file_path = ?, album_id = ? WHERE album_id = ? and file_path = ?");
$stmt->execute(array($newpath, $newAlbumId, $oldAlbumId, $oldpath)); $stmt->execute(array($newpath, $newAlbumId, $oldAlbumId, $oldpath));
} }

14
apps/gallery/lib/sharing.php Normal file → Executable file
View File

@ -24,7 +24,7 @@
class OC_Gallery_Sharing { class OC_Gallery_Sharing {
private static function getEntries($token) { private static function getEntries($token) {
$sql = 'SELECT * FROM *PREFIX*gallery_sharing WHERE token = ?'; $sql = 'SELECT * FROM *PREFIX*gallery_sharing WHERE token = ?';
$stmt = OC_DB::prepare($sql); $stmt = OCP\DB::prepare($sql);
return $stmt->execute(array($token)); return $stmt->execute(array($token));
} }
@ -45,7 +45,7 @@ class OC_Gallery_Sharing {
if ($row = $r->fetchRow()) { if ($row = $r->fetchRow()) {
$galleryId = $row['gallery_id']; $galleryId = $row['gallery_id'];
$sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE album_id = ?'; $sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE album_id = ?';
$stmt = OC_DB::prepare($sql); $stmt = OCP\DB::prepare($sql);
$r = $stmt->execute(array($galleryId)); $r = $stmt->execute(array($galleryId));
if ($row = $r->fetchRow()) if ($row = $r->fetchRow())
return $row['uid_owner']; return $row['uid_owner'];
@ -58,7 +58,7 @@ class OC_Gallery_Sharing {
if ($row = $r->fetchRow()) { if ($row = $r->fetchRow()) {
$galleryId = $row['gallery_id']; $galleryId = $row['gallery_id'];
$sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE album_id = ?'; $sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE album_id = ?';
$stmt = OC_DB::prepare($sql); $stmt = OCP\DB::prepare($sql);
$r = $stmt->execute(array($galleryId)); $r = $stmt->execute(array($galleryId));
if ($row = $r->fetchRow()) if ($row = $r->fetchRow())
return $row['album_path']; return $row['album_path'];
@ -66,23 +66,23 @@ class OC_Gallery_Sharing {
} }
public static function updateSharingByToken($token, $recursive) { public static function updateSharingByToken($token, $recursive) {
$stmt = OC_DB::prepare('UPDATE *PREFIX*gallery_sharing SET recursive = ? WHERE token = ?'); $stmt = OCP\DB::prepare('UPDATE *PREFIX*gallery_sharing SET recursive = ? WHERE token = ?');
$stmt->execute(array($recursive, $token)); $stmt->execute(array($recursive, $token));
} }
public static function getEntryByAlbumId($album_id) { public static function getEntryByAlbumId($album_id) {
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_sharing WHERE gallery_id = ?'); $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*gallery_sharing WHERE gallery_id = ?');
return $stmt->execute(array($album_id)); return $stmt->execute(array($album_id));
} }
public static function addShared($token, $albumId, $recursive) { public static function addShared($token, $albumId, $recursive) {
$sql = 'INSERT INTO *PREFIX*gallery_sharing (token, gallery_id, recursive) VALUES (?, ?, ?)'; $sql = 'INSERT INTO *PREFIX*gallery_sharing (token, gallery_id, recursive) VALUES (?, ?, ?)';
$stmt = OC_DB::prepare($sql); $stmt = OCP\DB::prepare($sql);
$stmt->execute(array($token, $albumId, $recursive)); $stmt->execute(array($token, $albumId, $recursive));
} }
public static function remove($albumId) { public static function remove($albumId) {
$stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_sharing WHERE gallery_id = ?'); $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*gallery_sharing WHERE gallery_id = ?');
$stmt->execute(array($albumId)); $stmt->execute(array($albumId));
} }
} }

View File

@ -67,12 +67,12 @@ if($arguments['action']){
OCP\JSON::encodedPrint($data); OCP\JSON::encodedPrint($data);
break; break;
case 'scan': case 'scan':
OC_DB::beginTransaction(); OCP\DB::beginTransaction();
set_time_limit(0); //recursive scan can take a while set_time_limit(0); //recursive scan can take a while
$eventSource=new OC_EventSource(); $eventSource=new OC_EventSource();
OC_MEDIA_SCANNER::scanCollection($eventSource); OC_MEDIA_SCANNER::scanCollection($eventSource);
$eventSource->close(); $eventSource->close();
OC_DB::commit(); OCP\DB::commit();
break; break;
case 'scanFile': case 'scanFile':
echo (OC_MEDIA_SCANNER::scanFile($arguments['path']))?'true':'false'; echo (OC_MEDIA_SCANNER::scanFile($arguments['path']))?'true':'false';

View File

@ -65,7 +65,7 @@ class OC_MEDIA_AMPACHE{
</root>"); </root>");
} }
if($auth and $user and $time){ if($auth and $user and $time){
$query=OC_DB::prepare("SELECT user_id, user_password_sha256 from *PREFIX*media_users WHERE user_id=?"); $query=OCP\DB::prepare("SELECT user_id, user_password_sha256 from *PREFIX*media_users WHERE user_id=?");
$users=$query->execute(array($user))->fetchAll(); $users=$query->execute(array($user))->fetchAll();
if(count($users)>0){ if(count($users)>0){
$pass=$users[0]['user_password_sha256']; $pass=$users[0]['user_password_sha256'];
@ -77,7 +77,7 @@ class OC_MEDIA_AMPACHE{
$songs=OC_MEDIA_COLLECTION::getSongCount(); $songs=OC_MEDIA_COLLECTION::getSongCount();
$artists=OC_MEDIA_COLLECTION::getArtistCount(); $artists=OC_MEDIA_COLLECTION::getArtistCount();
$albums=OC_MEDIA_COLLECTION::getAlbumCount(); $albums=OC_MEDIA_COLLECTION::getAlbumCount();
$query=OC_DB::prepare("INSERT INTO *PREFIX*media_sessions (`session_id`, `token`, `user_id`, `start`) VALUES (NULL, ?, ?, now());"); $query=OCP\DB::prepare("INSERT INTO *PREFIX*media_sessions (`session_id`, `token`, `user_id`, `start`) VALUES (NULL, ?, ?, now());");
$query->execute(array($token,$user)); $query->execute(array($token,$user));
$expire=date('c',time()+600); $expire=date('c',time()+600);
echo('<?xml version="1.0" encoding="UTF-8"?>'); echo('<?xml version="1.0" encoding="UTF-8"?>');
@ -137,10 +137,10 @@ class OC_MEDIA_AMPACHE{
} }
} }
//remove old sessions //remove old sessions
$query=OC_DB::prepare("DELETE from *PREFIX*media_sessions WHERE start<(NOW()-600)"); $query=OCP\DB::prepare("DELETE from *PREFIX*media_sessions WHERE start<(NOW()-600)");
$query->execute(); $query->execute();
$query=OC_DB::prepare("SELECT user_id from *PREFIX*media_sessions WHERE token=?"); $query=OCP\DB::prepare("SELECT user_id from *PREFIX*media_sessions WHERE token=?");
$users=$query->execute(array($auth))->fetchAll(); $users=$query->execute(array($auth))->fetchAll();
if(count($users)>0){ if(count($users)>0){
OC_MEDIA_COLLECTION::$uid=$users[0]['user_id']; OC_MEDIA_COLLECTION::$uid=$users[0]['user_id'];
@ -151,7 +151,7 @@ class OC_MEDIA_AMPACHE{
} }
public static function updateAuth($auth){ public static function updateAuth($auth){
$query=OC_DB::prepare("UPDATE *PREFIX*media_sessions SET start=CURRENT_TIMESTAMP WHERE token=?"); $query=OCP\DB::prepare("UPDATE *PREFIX*media_sessions SET start=CURRENT_TIMESTAMP WHERE token=?");
$query->execute(array($auth)); $query->execute(array($auth));
} }

View File

@ -43,7 +43,7 @@ class OC_MEDIA_COLLECTION{
if(isset(self::$artistIdCache[$name])){ if(isset(self::$artistIdCache[$name])){
return self::$artistIdCache[$name]; return self::$artistIdCache[$name];
}else{ }else{
$query=OC_DB::prepare("SELECT artist_id FROM *PREFIX*media_artists WHERE lower(artist_name) LIKE ?"); $query=OCP\DB::prepare("SELECT artist_id FROM *PREFIX*media_artists WHERE lower(artist_name) LIKE ?");
$artists=$query->execute(array($name))->fetchAll(); $artists=$query->execute(array($name))->fetchAll();
if(is_array($artists) and isset($artists[0])){ if(is_array($artists) and isset($artists[0])){
self::$artistIdCache[$name]=$artists[0]['artist_id']; self::$artistIdCache[$name]=$artists[0]['artist_id'];
@ -71,7 +71,7 @@ class OC_MEDIA_COLLECTION{
if(isset(self::$albumIdCache[$artistId][$name])){ if(isset(self::$albumIdCache[$artistId][$name])){
return self::$albumIdCache[$artistId][$name]; return self::$albumIdCache[$artistId][$name];
}else{ }else{
$query=OC_DB::prepare("SELECT album_id FROM *PREFIX*media_albums WHERE lower(album_name) LIKE ? AND album_artist=?"); $query=OCP\DB::prepare("SELECT album_id FROM *PREFIX*media_albums WHERE lower(album_name) LIKE ? AND album_artist=?");
$albums=$query->execute(array($name,$artistId))->fetchAll(); $albums=$query->execute(array($name,$artistId))->fetchAll();
if(is_array($albums) and isset($albums[0])){ if(is_array($albums) and isset($albums[0])){
self::$albumIdCache[$artistId][$name]=$albums[0]['album_id']; self::$albumIdCache[$artistId][$name]=$albums[0]['album_id'];
@ -104,7 +104,7 @@ class OC_MEDIA_COLLECTION{
return self::$albumIdCache[$artistId][$albumId][$name]; return self::$albumIdCache[$artistId][$albumId][$name];
}else{ }else{
$uid=$_SESSION['user_id']; $uid=$_SESSION['user_id'];
$query=OC_DB::prepare("SELECT song_id FROM *PREFIX*media_songs WHERE song_user=? AND song_name LIKE ? AND song_artist=? AND song_album=?"); $query=OCP\DB::prepare("SELECT song_id FROM *PREFIX*media_songs WHERE song_user=? AND song_name LIKE ? AND song_artist=? AND song_album=?");
$songs=$query->execute(array($uid,$name,$artistId,$albumId))->fetchAll(); $songs=$query->execute(array($uid,$name,$artistId,$albumId))->fetchAll();
if(is_array($songs) and isset($songs[0])){ if(is_array($songs) and isset($songs[0])){
self::$albumIdCache[$artistId][$albumId][$name]=$songs[0]['song_id']; self::$albumIdCache[$artistId][$albumId][$name]=$songs[0]['song_id'];
@ -130,7 +130,7 @@ class OC_MEDIA_COLLECTION{
}elseif($search==''){ }elseif($search==''){
$search='%'; $search='%';
} }
$query=OC_DB::prepare("SELECT DISTINCT artist_name, artist_id FROM *PREFIX*media_artists $query=OCP\DB::prepare("SELECT DISTINCT artist_name, artist_id FROM *PREFIX*media_artists
INNER JOIN *PREFIX*media_songs ON artist_id=song_artist WHERE artist_name LIKE ? AND song_user=? ORDER BY artist_name"); INNER JOIN *PREFIX*media_songs ON artist_id=song_artist WHERE artist_name LIKE ? AND song_user=? ORDER BY artist_name");
$result=$query->execute(array($search,self::$uid)); $result=$query->execute(array($search,self::$uid));
return $result->fetchAll(); return $result->fetchAll();
@ -151,7 +151,7 @@ class OC_MEDIA_COLLECTION{
if($artistId!=0){ if($artistId!=0){
return $artistId; return $artistId;
}else{ }else{
$query=OC_DB::prepare("INSERT INTO `*PREFIX*media_artists` (`artist_name`) VALUES (?)"); $query=OCP\DB::prepare("INSERT INTO `*PREFIX*media_artists` (`artist_name`) VALUES (?)");
$result=$query->execute(array($name)); $result=$query->execute(array($name));
return self::getArtistId($name);; return self::getArtistId($name);;
} }
@ -183,7 +183,7 @@ class OC_MEDIA_COLLECTION{
array_push($params,$search); array_push($params,$search);
} }
$cmd.=' ORDER BY album_name'; $cmd.=' ORDER BY album_name';
$query=OC_DB::prepare($cmd); $query=OCP\DB::prepare($cmd);
return $query->execute($params)->fetchAll(); return $query->execute($params)->fetchAll();
} }
@ -203,7 +203,7 @@ class OC_MEDIA_COLLECTION{
if($albumId!=0){ if($albumId!=0){
return $albumId; return $albumId;
}else{ }else{
$query=OC_DB::prepare("INSERT INTO `*PREFIX*media_albums` (`album_name` ,`album_artist`) VALUES ( ?, ?)"); $query=OCP\DB::prepare("INSERT INTO `*PREFIX*media_albums` (`album_name` ,`album_artist`) VALUES ( ?, ?)");
$query->execute(array($name,$artist)); $query->execute(array($name,$artist));
return self::getAlbumId($name,$artist); return self::getAlbumId($name,$artist);
} }
@ -243,7 +243,7 @@ class OC_MEDIA_COLLECTION{
}else{ }else{
$searchString=''; $searchString='';
} }
$query=OC_DB::prepare("SELECT * FROM *PREFIX*media_songs WHERE song_user=? $artistString $albumString $searchString ORDER BY song_track, song_name, song_path"); $query=OCP\DB::prepare("SELECT * FROM *PREFIX*media_songs WHERE song_user=? $artistString $albumString $searchString ORDER BY song_track, song_name, song_path");
return $query->execute($params)->fetchAll(); return $query->execute($params)->fetchAll();
} }
@ -270,39 +270,39 @@ class OC_MEDIA_COLLECTION{
return $songId; return $songId;
}else{ }else{
if(!isset(self::$queries['addsong'])){ if(!isset(self::$queries['addsong'])){
$query=OC_DB::prepare("INSERT INTO `*PREFIX*media_songs` (`song_name` ,`song_artist` ,`song_album` ,`song_path` ,`song_user`,`song_length`,`song_track`,`song_size`,`song_playcount`,`song_lastplayed`) $query=OCP\DB::prepare("INSERT INTO `*PREFIX*media_songs` (`song_name` ,`song_artist` ,`song_album` ,`song_path` ,`song_user`,`song_length`,`song_track`,`song_size`,`song_playcount`,`song_lastplayed`)
VALUES (?, ?, ?, ?,?,?,?,?,0,0)"); VALUES (?, ?, ?, ?,?,?,?,?,0,0)");
self::$queries['addsong']=$query; self::$queries['addsong']=$query;
}else{ }else{
$query=self::$queries['addsong']; $query=self::$queries['addsong'];
} }
$query->execute(array($name,$artist,$album,$path,$uid,$length,$track,$size)); $query->execute(array($name,$artist,$album,$path,$uid,$length,$track,$size));
$songId=OC_DB::insertid('*PREFIX*media_songs'); $songId=OCP\DB::insertid('*PREFIX*media_songs');
// self::setLastUpdated(); // self::setLastUpdated();
return self::getSongId($name,$artist,$album); return self::getSongId($name,$artist,$album);
} }
} }
public static function getSongCount(){ public static function getSongCount(){
$query=OC_DB::prepare("SELECT COUNT(song_id) AS count FROM *PREFIX*media_songs"); $query=OCP\DB::prepare("SELECT COUNT(song_id) AS count FROM *PREFIX*media_songs");
$result=$query->execute()->fetchAll(); $result=$query->execute()->fetchAll();
return $result[0]['count']; return $result[0]['count'];
} }
public static function getArtistCount(){ public static function getArtistCount(){
$query=OC_DB::prepare("SELECT COUNT(artist_id) AS count FROM *PREFIX*media_artists"); $query=OCP\DB::prepare("SELECT COUNT(artist_id) AS count FROM *PREFIX*media_artists");
$result=$query->execute()->fetchAll(); $result=$query->execute()->fetchAll();
return $result[0]['count']; return $result[0]['count'];
} }
public static function getAlbumCount(){ public static function getAlbumCount(){
$query=OC_DB::prepare("SELECT COUNT(album_id) AS count FROM *PREFIX*media_albums"); $query=OCP\DB::prepare("SELECT COUNT(album_id) AS count FROM *PREFIX*media_albums");
$result=$query->execute()->fetchAll(); $result=$query->execute()->fetchAll();
return $result[0]['count']; return $result[0]['count'];
} }
public static function getArtistName($artistId){ public static function getArtistName($artistId){
$query=OC_DB::prepare("SELECT artist_name FROM *PREFIX*media_artists WHERE artist_id=?"); $query=OCP\DB::prepare("SELECT artist_name FROM *PREFIX*media_artists WHERE artist_id=?");
$artist=$query->execute(array($artistId))->fetchAll(); $artist=$query->execute(array($artistId))->fetchAll();
if(count($artist)>0){ if(count($artist)>0){
return $artist[0]['artist_name']; return $artist[0]['artist_name'];
@ -312,7 +312,7 @@ class OC_MEDIA_COLLECTION{
} }
public static function getAlbumName($albumId){ public static function getAlbumName($albumId){
$query=OC_DB::prepare("SELECT album_name FROM *PREFIX*media_albums WHERE album_id=?"); $query=OCP\DB::prepare("SELECT album_name FROM *PREFIX*media_albums WHERE album_id=?");
$album=$query->execute(array($albumId))->fetchAll(); $album=$query->execute(array($albumId))->fetchAll();
if(count($album)>0){ if(count($album)>0){
return $album[0]['album_name']; return $album[0]['album_name'];
@ -322,7 +322,7 @@ class OC_MEDIA_COLLECTION{
} }
public static function getSong($id){ public static function getSong($id){
$query=OC_DB::prepare("SELECT * FROM *PREFIX*media_songs WHERE song_id=?"); $query=OCP\DB::prepare("SELECT * FROM *PREFIX*media_songs WHERE song_id=?");
$song=$query->execute(array($id))->fetchAll(); $song=$query->execute(array($id))->fetchAll();
if(count($song)>0){ if(count($song)>0){
return $song[0]; return $song[0];
@ -336,7 +336,7 @@ class OC_MEDIA_COLLECTION{
* @param string $path * @param string $path
*/ */
public static function getSongCountByPath($path){ public static function getSongCountByPath($path){
$query=OC_DB::prepare("SELECT COUNT(song_id) AS count FROM *PREFIX*media_songs WHERE song_path LIKE ?"); $query=OCP\DB::prepare("SELECT COUNT(song_id) AS count FROM *PREFIX*media_songs WHERE song_path LIKE ?");
$result=$query->execute(array("$path%"))->fetchAll(); $result=$query->execute(array("$path%"))->fetchAll();
return $result[0]['count']; return $result[0]['count'];
} }
@ -348,7 +348,7 @@ class OC_MEDIA_COLLECTION{
* if a path of a folder is passed, all songs stored in the folder will be removed from the database * if a path of a folder is passed, all songs stored in the folder will be removed from the database
*/ */
public static function deleteSongByPath($path){ public static function deleteSongByPath($path){
$query=OC_DB::prepare("DELETE FROM *PREFIX*media_songs WHERE song_path LIKE ?"); $query=OCP\DB::prepare("DELETE FROM *PREFIX*media_songs WHERE song_path LIKE ?");
$query->execute(array("$path%")); $query->execute(array("$path%"));
} }
@ -358,7 +358,7 @@ class OC_MEDIA_COLLECTION{
*/ */
public static function registerPlay($songId){ public static function registerPlay($songId){
$now=time(); $now=time();
$query=OC_DB::prepare('UPDATE *PREFIX*media_songs SET song_playcount=song_playcount+1, song_lastplayed=? WHERE song_id=? AND song_lastplayed<?'); $query=OCP\DB::prepare('UPDATE *PREFIX*media_songs SET song_playcount=song_playcount+1, song_lastplayed=? WHERE song_id=? AND song_lastplayed<?');
$query->execute(array($now,$songId,$now-60)); $query->execute(array($now,$songId,$now-60));
} }
@ -368,7 +368,7 @@ class OC_MEDIA_COLLECTION{
* @return int * @return int
*/ */
public static function getSongByPath($path){ public static function getSongByPath($path){
$query=OC_DB::prepare("SELECT song_id FROM *PREFIX*media_songs WHERE song_path = ?"); $query=OCP\DB::prepare("SELECT song_id FROM *PREFIX*media_songs WHERE song_path = ?");
$result=$query->execute(array($path)); $result=$query->execute(array($path));
if($row=$result->fetchRow()){ if($row=$result->fetchRow()){
return $row['song_id']; return $row['song_id'];
@ -383,7 +383,7 @@ class OC_MEDIA_COLLECTION{
* @param string $newPath * @param string $newPath
*/ */
public static function moveSong($oldPath,$newPath){ public static function moveSong($oldPath,$newPath){
$query=OC_DB::prepare("UPDATE *PREFIX*media_songs SET song_path = ? WHERE song_path = ?"); $query=OCP\DB::prepare("UPDATE *PREFIX*media_songs SET song_path = ? WHERE song_path = ?");
$query->execute(array($newPath,$oldPath)); $query->execute(array($newPath,$oldPath));
} }
} }

View File

@ -41,11 +41,11 @@ class OC_MEDIA{
public static function loginListener($params){ public static function loginListener($params){
if(isset($_POST['user']) and $_POST['password']){ if(isset($_POST['user']) and $_POST['password']){
$name=$_POST['user']; $name=$_POST['user'];
$query=OC_DB::prepare("SELECT user_id from *PREFIX*media_users WHERE user_id LIKE ?"); $query=OCP\DB::prepare("SELECT user_id from *PREFIX*media_users WHERE user_id LIKE ?");
$uid=$query->execute(array($name))->fetchAll(); $uid=$query->execute(array($name))->fetchAll();
if(count($uid)==0){ if(count($uid)==0){
$password=hash('sha256',$_POST['password']); $password=hash('sha256',$_POST['password']);
$query=OC_DB::prepare("INSERT INTO *PREFIX*media_users (user_id, user_password_sha256) VALUES (?, ?);"); $query=OCP\DB::prepare("INSERT INTO *PREFIX*media_users (user_id, user_password_sha256) VALUES (?, ?);");
$query->execute(array($name,$password)); $query->execute(array($name,$password));
} }
} }

View File

@ -2,7 +2,7 @@
class OC_remoteStorage { class OC_remoteStorage {
public static function getValidTokens($ownCloudUser, $category) { public static function getValidTokens($ownCloudUser, $category) {
$query=OC_DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100"); $query=OCP\DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100");
$result=$query->execute(array($ownCloudUser)); $result=$query->execute(array($ownCloudUser));
$ret = array(); $ret = array();
while($row=$result->fetchRow()){ while($row=$result->fetchRow()){
@ -15,7 +15,7 @@ class OC_remoteStorage {
public static function getAllTokens() { public static function getAllTokens() {
$user=OCP\USER::getUser(); $user=OCP\USER::getUser();
$query=OC_DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100"); $query=OCP\DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100");
$result=$query->execute(array($user)); $result=$query->execute(array($user));
$ret = array(); $ret = array();
while($row=$result->fetchRow()){ while($row=$result->fetchRow()){
@ -29,13 +29,13 @@ class OC_remoteStorage {
public static function deleteToken($token) { public static function deleteToken($token) {
$user=OCP\USER::getUser(); $user=OCP\USER::getUser();
$query=OC_DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?"); $query=OCP\DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?");
$result=$query->execute(array($token,$user)); $result=$query->execute(array($token,$user));
return 'unknown';//how can we see if any rows were affected? return 'unknown';//how can we see if any rows were affected?
} }
private static function addToken($token, $appUrl, $categories){ private static function addToken($token, $appUrl, $categories){
$user=OCP\USER::getUser(); $user=OCP\USER::getUser();
$query=OC_DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)"); $query=OCP\DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)");
$result=$query->execute(array($token,$appUrl,$user,$categories)); $result=$query->execute(array($token,$appUrl,$user,$categories));
} }
public static function createCategories($appUrl, $categories) { public static function createCategories($appUrl, $categories) {

View File

@ -137,7 +137,7 @@ class OC_LDAP {
static private function ocname2dn($name, $isUser) { static private function ocname2dn($name, $isUser) {
$table = self::getMapTable($isUser); $table = self::getMapTable($isUser);
$query = OC_DB::prepare(' $query = OCP\DB::prepare('
SELECT ldap_dn SELECT ldap_dn
FROM '.$table.' FROM '.$table.'
WHERE owncloud_name = ? WHERE owncloud_name = ?
@ -189,7 +189,7 @@ class OC_LDAP {
$nameAttribute = self::conf('ldapGroupDisplayName'); $nameAttribute = self::conf('ldapGroupDisplayName');
} }
$query = OC_DB::prepare(' $query = OCP\DB::prepare('
SELECT owncloud_name SELECT owncloud_name
FROM '.$table.' FROM '.$table.'
WHERE ldap_dn = ? WHERE ldap_dn = ?
@ -316,7 +316,7 @@ class OC_LDAP {
static private function mappedComponents($isUsers) { static private function mappedComponents($isUsers) {
$table = self::getMapTable($isUsers); $table = self::getMapTable($isUsers);
$query = OC_DB::prepare(' $query = OCP\DB::prepare('
SELECT ldap_dn, owncloud_name SELECT ldap_dn, owncloud_name
FROM '. $table FROM '. $table
); );
@ -360,7 +360,7 @@ class OC_LDAP {
static private function mapComponent($dn, $ocname, $isUser = true) { static private function mapComponent($dn, $ocname, $isUser = true) {
$table = self::getMapTable($isUser); $table = self::getMapTable($isUser);
$insert = OC_DB::prepare(' $insert = OCP\DB::prepare('
INSERT IGNORE INTO '.$table.' INSERT IGNORE INTO '.$table.'
(ldap_dn, owncloud_name) (ldap_dn, owncloud_name)
VALUES (?,?) VALUES (?,?)
@ -368,7 +368,7 @@ class OC_LDAP {
$res = $insert->execute(array($dn, $ocname)); $res = $insert->execute(array($dn, $ocname));
return !OC_DB::isError($res); return !OCP\DB::isError($res);
} }
/** /**

2
apps/user_openid/user_openid.php Normal file → Executable file
View File

@ -54,7 +54,7 @@ class OC_USER_OPENID extends OC_User_Backend {
* find the user that can be authenticated with an openid identity * find the user that can be authenticated with an openid identity
*/ */
public static function findUserForIdentity($identity){ public static function findUserForIdentity($identity){
$query=OC_DB::prepare('SELECT userid FROM *PREFIX*preferences WHERE appid=? AND configkey=? AND configvalue=?'); $query=OCP\DB::prepare('SELECT userid FROM *PREFIX*preferences WHERE appid=? AND configkey=? AND configvalue=?');
$result=$query->execute(array('user_openid','identity',$identity))->fetchAll(); $result=$query->execute(array('user_openid','identity',$identity))->fetchAll();
if(count($result)>0){ if(count($result)>0){
return $result[0]['userid']; return $result[0]['userid'];

92
lib/public/db.php Normal file
View File

@ -0,0 +1,92 @@
<?php
/**
* ownCloud
*
* @author Frank Karlitschek
* @copyright 2010 Frank Karlitschek karlitschek@kde.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Public interface of ownCloud for apps to use.
* DB Class
*
*/
// use OCP namespace for all classes that are considered public.
// This means that they should be used by apps instead of the internal ownCloud classes
namespace OCP;
class DB {
/**
* @brief Prepare a SQL query
* @param $query Query string
* @returns prepared SQL query
*
* SQL query via MDB2 prepare(), needs to be execute()'d!
*/
static public function prepare( $query ){
return(\OC_DB::prepare($query));
}
/**
* @brief gets last value of autoincrement
* @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix
* @returns id
*
* MDB2 lastInsertID()
*
* Call this method right after the insert command or other functions may
* cause trouble!
*/
public static function insertid($table=null){
return(\OC_DB::insertid($table));
}
/**
* Start a transaction
*/
public static function beginTransaction(){
return(\OC_DB::beginTransaction());
}
/**
* Commit the database changes done during a transaction that is in progress
*/
public static function commit(){
return(\OC_DB::commit());
}
/**
* check if a result is an error, works with MDB2 and PDOException
* @param mixed $result
* @return bool
*/
public static function isError($result){
return(\OC_DB::isError($result));
}
}
?>