function handleGalleryScanning() { OCP\DB::beginTransaction(); set_time_limit(0); OC_Gallery_Album::cleanup(); $eventSource = new OC_EventSource(); OC_Gallery_Scanner::scan($eventSource); $eventSource->close(); OCP\DB::commit(); }
set_time_limit(0); //scanning can take ages $force = isset($_GET['force']) and $_GET['force'] == 'true'; $dir = isset($_GET['dir']) ? $_GET['dir'] : ''; $checkOnly = isset($_GET['checkonly']) and $_GET['checkonly'] == 'true'; if (!$checkOnly) { $eventSource = new OC_EventSource(); } //create the file cache if necesary if ($force or !OC_FileCache::inCache('')) { if (!$checkOnly) { OCP\DB::beginTransaction(); OC_FileCache::scan($dir, $eventSource); OC_FileCache::clean(); OCP\DB::commit(); $eventSource->send('success', true); } else { OCP\JSON::success(array('data' => array('done' => true))); exit; } } else { if ($checkOnly) { OCP\JSON::success(array('data' => array('done' => false))); exit; } if (isset($eventSource)) { $eventSource->send('success', false); } else { exit; }
/** * @brief Delete all the posts created by the given member * @param Member whos posts have to be deleted * @param Whether the calling method has already initiated the (database) transaction */ public static function removePostsByMember($member, $inTransaction = false) { try { if (!$inTransaction) { OCP\DB::beginTransaction(); } $del_notification = OCP\DB::prepare('DELETE FROM `*PREFIX*collaboration_notification` WHERE `visible_to`=?'); $del_comment = OCP\DB::prepare('DELETE FROM `*PREFIX*collaboration_comment` WHERE `creator`=?'); $query = OCP\DB::prepare('SELECT `post_id` FROM `*PREFIX*collaboration_post` WHERE `creator`=?'); $result = $query->execute(array($member)); while ($row = $result->fetchRow()) { self::deletePost($row['post_id'], true); } $del_notification->execute(array($member)); $del_comment->execute(array($member)); if (!$inTransaction) { OCP\DB::commit(); } } catch (\Exception $e) { OC_Log::write('collaboration', __METHOD__ . ', Exception: ' . $e->getMessage(), OCP\Util::DEBUG); return false; } }
public static function importFile($file) { libxml_use_internal_errors(true); $dom = new domDocument(); $dom->loadHTMLFile($file); $links = $dom->getElementsByTagName('a'); OCP\DB::beginTransaction(); foreach ($links as $link) { $title = $link->nodeValue; $ref = $link->getAttribute("href"); $tag_str = ''; if ($link->hasAttribute("tags")) { $tag_str = $link->getAttribute("tags"); } $tags = explode(',', $tag_str); $desc_str = ''; if ($link->hasAttribute("description")) { $desc_str = $link->getAttribute("description"); } self::addBookmark($ref, $title, $tags, $desc_str); } OCP\DB::commit(); return array(); }
/** * @brief send a new notification to the given user * @param $appid app which sends the notification * @param $class id relating to a template in the app's info.xml * @param $uid receiving user * @param $params keys and values for placeholders in the template and href/img * @return id of the inserted notification, null if unsuccessful */ public static function sendUserNotification($appid, $class, $uid, $params = array()) { try { $classId = self::getClassId($appid, $class); if ($classId === false) { throw new Exception("Notification template {$appid}/{$class} not found"); } if (self::isBlacklisted($uid, $classId)) { return null; } OCP\DB::beginTransaction(); if (!isset(self::$notifyStmt)) { self::$notifyStmt = OCP\DB::prepare("INSERT INTO *PREFIX*notifications (class, uid, moment) VALUES (?, ?, NOW())"); } OC_Hook::emit("notify", "pre_sendUserNotification", array("classId" => $classId, "uid" => $uid, "params" => $params)); self::$notifyStmt->execute(array($classId, $uid)); $id = OCP\DB::insertid("*PREFIX*notifications"); if (count($params)) { if (!isset(self::$paramStmt)) { self::$paramStmt = OCP\DB::prepare("INSERT INTO *PREFIX*notification_params (nid, key, value) VALUES ({$id}, ?, ?)"); } foreach ($params as $key => $value) { self::$paramStmt->execute(array($key, $value)); OCP\DB::insertid("*PREFIX*notification_params"); } } OCP\DB::commit(); OC_Hook::emit("notify", "post_sendUserNotification", array("id" => $id, "classId" => $classId, "uid" => $uid, "params" => $params)); return (int) $id; } catch (Exception $e) { OCP\Util::writeLog("notify", "Could not send notification: " . $e->getMessage(), OCP\Util::ERROR); throw $e; /* TODO: good exception handling and throwing, e.g.: * - throw exception when there are errors * - return false (or null?) when the app/class is blacklisted */ } }
/** * @brief Unassign all the tasks performed by the given member * @param Member whose tasks have to be unassigned * @param Project ID * @param Member who removes the other member * @param Whether the calling method has already initiated the (database) transaction */ public static function unassignMembersTasks($member, $pid, $remover, $inTransaction) { try { if (!$inTransaction) { OCP\DB::beginTransaction(); } $query = \OCP\DB::prepare('SELECT `tstatus`.`tid`, `task`.`title` FROM `*PREFIX*collaboration_task_status` AS tstatus, `*PREFIX*collaboration_task` AS task, `*PREFIX*collaboration_project` AS project WHERE ' . (is_null($pid) ? '' : ' `project`.`pid`=? AND ') . '`project`.`completed`=false AND `tstatus`.`tid`=`task`.`tid` AND `task`.`pid`=`project`.`pid` AND (`status`=\'In Progress\' OR `status`=\'Held\') AND `member`=? AND `tstatus`.`last_updated_time`= (SELECT MAX(`last_updated_time`) FROM `*PREFIX*collaboration_task_status` WHERE `tid`=`tstatus`.`tid`)'); $args = array(); if (is_null($pid)) { $args[0] = $member; } else { $args[0] = $pid; $args[1] = $member; } $result = $query->execute($args); $reason = 'User removed from ' . (is_null($pid) ? 'owncloud' : OC_Collaboration_Project::getProjectTitle($pid)); while ($row = $result->fetchRow()) { self::changeStatus($row['tid'], $row['title'], 'Unassigned', $remover, NULL, $reason, true); } if (!$inTransaction) { OCP\DB::commit(); } } catch (\Exception $e) { OC_Log::write('collaboration', __METHOD__ . ', Exception: ' . $e->getMessage(), OCP\Util::DEBUG); return false; } }