public function upgradePath($path) { $this->count++; if ($this->count > $this->lastSend + 5) { $this->lastSend = $this->count; $this->eventSource->send('count', $this->count); } }
/** * index the given fileId or, if not given, all unindexed files * @param int $fileId optional fileId to index * @NoAdminRequired */ public function index($fileId = null) { if (isset($fileId)) { $fileIds = array($fileId); } else { $fileIds = $this->mapper->getUnindexed(); } //TODO use public api when available in \OCP\AppFramework\IApi $eventSource = new \OC_EventSource(); $eventSource->send('count', count($fileIds)); $this->indexer->indexFiles($fileIds, $eventSource); $eventSource->send('done', ''); $eventSource->close(); // end script execution to prevent app framework from sending headers after // the eventsource is closed exit; }
function index() { if (isset($_GET['fileid'])) { $fileIds = array($_GET['fileid']); } else { $fileIds = OCA\Search_Lucene\Indexer::getUnindexed(); } $eventSource = new OC_EventSource(); $eventSource->send('count', count($fileIds)); $skippedDirs = explode(';', OCP\Config::getUserValue(OCP\User::getUser(), 'search_lucene', 'skipped_dirs', '.git;.svn;.CVS;.bzr')); foreach ($fileIds as $id) { $skipped = false; $fileStatus = OCA\Search_Lucene\Status::fromFileId($id); try { //before we start mark the file as error so we know there was a problem when the php execution dies $fileStatus->markError(); $path = OC\Files\Filesystem::getPath($id); $eventSource->send('indexing', $path); foreach ($skippedDirs as $skippedDir) { if (strpos($path, '/' . $skippedDir . '/') !== false || strrpos($path, '/' . $skippedDir) === strlen($path) - (strlen($skippedDir) + 1)) { $result = $fileStatus->markSkipped(); $skipped = true; break; } } if (!$skipped) { if (OCA\Search_Lucene\Indexer::indexFile($path, OCP\User::getUser())) { $result = $fileStatus->markIndexed(); } } if (!$result) { OCP\JSON::error(array('message' => 'Could not index file.')); $eventSource->send('error', $path); } } catch (Exception $e) { //sqlite might report database locked errors when stock filescan is in progress //this also catches db locked exception that might come up when using sqlite \OCP\Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), \OCP\Util::ERROR); OCP\JSON::error(array('message' => 'Could not index file.')); $eventSource->send('error', $e->getMessage()); //try to mark the file as new to let it reindex $fileStatus->markNew(); // Add UI to trigger rescan of files with status 'E'rror? } } $eventSource->send('done', ''); $eventSource->close(); }
function index() { $fileIds = OCA\Search_Lucene\Indexer::getUnindexed(); $eventSource = new OC_EventSource(); $eventSource->send('count', count($fileIds)); $skippedDirs = explode(';', OCP\Config::getUserValue(OCP\User::getUser(), 'search_lucene', 'skipped_dirs', '.git;.svn;.CVS;.bzr')); $query = OC_DB::prepare('INSERT INTO `*PREFIX*lucene_status` VALUES (?,?)'); foreach ($fileIds as $id) { $skipped = false; try { //before we start mark the file as error so we know there was a problem when the php execution dies $result = $query->execute(array($id, 'E')); $path = OC\Files\Filesystem::getPath($id); $eventSource->send('indexing', $path); //clean jobs for indexed file $param = json_encode(array('path' => $path, 'user' => OCP\User::getUser())); $cleanjobquery = OC_DB::prepare('DELETE FROM `*PREFIX*queuedtasks` WHERE `app`=? AND `parameters`=?'); $cleanjobquery->execute(array('search_lucene', $param)); foreach ($skippedDirs as $skippedDir) { if (strpos($path, '/' . $skippedDir . '/') !== false || strrpos($path, '/' . $skippedDir) === strlen($path) - (strlen($skippedDir) + 1)) { $result = $query->execute(array($id, 'S')); $skipped = true; break; } } if (!$skipped) { if (OCA\Search_Lucene\Indexer::indexFile($path, OCP\User::getUser())) { $result = $query->execute(array($id, 'I')); } } if (!$result) { OC_JSON::error(array('message' => 'Could not index file.')); $eventSource->send('error', $path); } } catch (PDOException $e) { //sqlite might report database locked errors when stock filescan is in progress //this also catches db locked exception that might come up when using sqlite \OCP\Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), \OCP\Util::ERROR); OC_JSON::error(array('message' => 'Could not index file.')); $eventSource->send('error', $e->getMessage()); //try to mark the file as new to let it reindex $query->execute(array($id, 'N')); // Add UI to trigger rescan of files with status 'E'rror? } } $eventSource->send('done', ''); $eventSource->close(); }
<?php // Init owncloud global $eventSource; if (!OC_User::isLoggedIn()) { exit; } session_write_close(); // Get the params $dir = isset($_REQUEST['dir']) ? '/' . trim($_REQUEST['dir'], '/\\') : ''; $filename = isset($_REQUEST['filename']) ? trim($_REQUEST['filename'], '/\\') : ''; $content = isset($_REQUEST['content']) ? $_REQUEST['content'] : ''; $source = isset($_REQUEST['source']) ? trim($_REQUEST['source'], '/\\') : ''; if ($source) { $eventSource = new OC_EventSource(); } else { OC_JSON::callCheck(); } function progress($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { static $filesize = 0; static $lastsize = 0; global $eventSource; switch ($notification_code) { case STREAM_NOTIFY_FILE_SIZE_IS: $filesize = $bytes_max; break; case STREAM_NOTIFY_PROGRESS: if ($bytes_transferred > 0) { if (!isset($filesize)) { } else {
$user = $rootLinkItem['uid_owner']; // Setup filesystem OCP\JSON::checkUserExists($user); OC_Util::tearDownFS(); OC_Util::setupFS($user); $root = \OC\Files\Filesystem::getPath($linkItem['file_source']) . '/'; $images = array_map(function ($image) use($root) { return $root . $image; }, $images); } else { $root = ''; OCP\JSON::checkLoggedIn(); $user = OCP\User::getUser(); } session_write_close(); $eventSource = new OC_EventSource(); foreach ($images as $image) { $height = 200 * $scale; if ($square) { $width = 200 * $scale; } else { $width = 400 * $scale; } $userView = new \OC\Files\View('/' . $user); $preview = new \OC\Preview($user, 'files', '/' . $image, $width, $height); $preview->setKeepAspect(!$square); $fileInfo = $userView->getFileInfo('/files/' . $image); // if the thumbnails is already cached, get it directly from the filesystem to avoid decoding and re-encoding the image $imageName = substr($image, strlen($root)); if ($path = $preview->isCached($fileInfo->getId())) { $eventSource->send('preview', array('image' => $imageName, 'preview' => base64_encode($userView->file_get_contents('/' . $path))));
<?php // Init owncloud global $eventSource; if (!OC_User::isLoggedIn()) { exit; } \OC::$session->close(); // Get the params $dir = isset($_REQUEST['dir']) ? '/' . trim($_REQUEST['dir'], '/\\') : ''; $filename = isset($_REQUEST['filename']) ? trim($_REQUEST['filename'], '/\\') : ''; $content = isset($_REQUEST['content']) ? $_REQUEST['content'] : ''; $source = isset($_REQUEST['source']) ? trim($_REQUEST['source'], '/\\') : ''; if ($source) { $eventSource = new OC_EventSource(); } else { OC_JSON::callCheck(); } function progress($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { static $filesize = 0; static $lastsize = 0; global $eventSource; switch ($notification_code) { case STREAM_NOTIFY_FILE_SIZE_IS: $filesize = $bytes_max; break; case STREAM_NOTIFY_PROGRESS: if ($bytes_transferred > 0) { if (!isset($filesize)) { } else {
// Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('news'); OCP\JSON::callCheck(); global $l; $l = OC_L10N::get('news'); function bailOut($msg) { global $eventSource; $eventSource->send('error', $msg); $eventSource->close(); OCP\Util::writeLog('news', 'ajax/importopml.php: ' . $msg, OCP\Util::ERROR); exit; } global $eventSource; $eventSource = new OC_EventSource(); require_once 'news/opmlparser.php'; $source = isset($_REQUEST['source']) ? $_REQUEST['source'] : ''; $path = isset($_REQUEST['path']) ? $_REQUEST['path'] : ''; if ($path == '') { bailOut($l->t('Empty filename')); exit; } if ($source == 'cloud') { $raw = file_get_contents($path); } elseif ($source == 'local') { $storage = \OCP\Files::getStorage('news'); $raw = $storage->file_get_contents($path); } else { bailOut($l->t('No source argument passed')); }
/** * @param array $fileIds * @param \OC_EventSource $eventSource */ public function indexFiles(array $fileIds, \OC_EventSource $eventSource = null) { foreach ($fileIds as $id) { $fileStatus = $this->mapper->getOrCreateFromFileId($id); try { // before we start mark the file as error so we know there // was a problem in case the php execution dies and we don't try // the file again $this->mapper->markError($fileStatus); $nodes = $this->server->getUserFolder()->getById($id); // getById can return more than one id because the containing storage might be mounted more than once // Since we only want to index the file once, we only use the first entry if (isset($nodes[0])) { /** @var File $node */ $node = $nodes[0]; } else { throw new VanishedException($id); } if (!$node instanceof File) { throw new NotIndexedException(); } $path = $node->getPath(); foreach ($this->skippedDirs as $skippedDir) { if (strpos($path, '/' . $skippedDir . '/') !== false || strrpos($path, '/' . $skippedDir) === strlen($path) - (strlen($skippedDir) + 1)) { throw new SkippedException('skipping file ' . $id . ':' . $path); } } if ($eventSource) { $eventSource->send('indexing', $path); } if ($this->indexFile($node, false)) { $this->mapper->markIndexed($fileStatus); } } catch (VanishedException $e) { $this->mapper->markVanished($fileStatus); } catch (NotIndexedException $e) { $this->mapper->markUnIndexed($fileStatus); } catch (SkippedException $e) { $this->mapper->markSkipped($fileStatus); $this->logger->debug($e->getMessage()); } catch (\Exception $e) { //sqlite might report database locked errors when stock filescan is in progress //this also catches db locked exception that might come up when using sqlite $this->logger->error($e->getMessage() . ' Trace:\\n' . $e->getTraceAsString()); $this->mapper->markError($fileStatus); // TODO Add UI to trigger rescan of files with status 'E'rror? if ($eventSource) { $eventSource->send('error', $e->getMessage()); } } } $this->index->commit(); }
<?php // Init owncloud global $eventSource; if (!OC_User::isLoggedIn()) { exit; } session_write_close(); // Get the params $dir = isset($_REQUEST['dir']) ? '/' . trim($_REQUEST['dir'], '/\\') : ''; $filename = isset($_REQUEST['filename']) ? trim($_REQUEST['filename'], '/\\') : ''; $content = isset($_REQUEST['content']) ? $_REQUEST['content'] : ''; $source = isset($_REQUEST['source']) ? trim($_REQUEST['source'], '/\\') : ''; if ($source) { $eventSource = new OC_EventSource(); } else { OC_JSON::callCheck(); } if ($filename == '') { OCP\JSON::error(array("data" => array("message" => "Empty Filename"))); exit; } if (strpos($filename, '/') !== false) { OCP\JSON::error(array("data" => array("message" => "Invalid Filename"))); exit; } function progress($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { static $filesize = 0; static $lastsize = 0; global $eventSource;
public function done() { $this->eventSource->send('done', $this->scannedCount); }
set_time_limit(0); //scanning can take ages session_write_close(); $force = (isset($_GET['force']) and $_GET['force'] === 'true'); $dir = isset($_GET['dir']) ? $_GET['dir'] : ''; if (isset($_GET['users'])) { OC_JSON::checkAdminUser(); if ($_GET['users'] === 'all') { $users = OC_User::getUsers(); } else { $users = json_decode($_GET['users']); } } else { $users = array(OC_User::getUser()); } $eventSource = new OC_EventSource(); $listener = new ScanListener($eventSource); foreach ($users as $user) { $eventSource->send('user', $user); $scanner = new \OC\Files\Utils\Scanner($user); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', array($listener, 'file')); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', array($listener, 'folder')); if ($force) { $scanner->scan($dir); } else { $scanner->backgroundScan($dir); } } $eventSource->send('done', $listener->getCount()); $eventSource->close(); class ScanListener
/** * recursively scan the filesystem and fill the cache * @param string $path * @param OC_EventSource $eventSource (optional) * @param int $count (optional) * @param string $root (optional) */ public static function scan($path, $eventSource = false, &$count = 0, $root = false) { if ($eventSource) { $eventSource->send('scanning', array('file' => $path, 'count' => $count)); } $lastSend = $count; // NOTE: Ugly hack to prevent shared files from going into the cache (the source already exists somewhere in the cache) if (substr($path, 0, 7) == '/Shared') { return; } if ($root === false) { $view = OC_Filesystem::getView(); } else { $view = new OC_FilesystemView($root); } self::scanFile($path, $root); $dh = $view->opendir($path . '/'); $totalSize = 0; if ($dh) { while (($filename = readdir($dh)) !== false) { if ($filename != '.' and $filename != '..') { $file = $path . '/' . $filename; if ($view->is_dir($file . '/')) { self::scan($file, $eventSource, $count, $root); } else { $totalSize += self::scanFile($file, $root); $count++; if ($count > $lastSend + 25 and $eventSource) { $lastSend = $count; $eventSource->send('scanning', array('file' => $path, 'count' => $count)); } } } } } OC_FileCache_Update::cleanFolder($path, $root); self::increaseSize($path, $totalSize, $root); }
set_time_limit(0); //scanning can take ages session_write_close(); $force = (isset($_GET['force']) and $_GET['force'] === 'true'); $dir = isset($_GET['dir']) ? $_GET['dir'] : ''; if (isset($_GET['users'])) { OC_JSON::checkAdminUser(); if ($_GET['users'] === 'all') { $users = OC_User::getUsers(); } else { $users = json_decode($_GET['users']); } } else { $users = array(OC_User::getUser()); } $eventSource = new OC_EventSource(); ScanListener::$eventSource = $eventSource; ScanListener::$view = \OC\Files\Filesystem::getView(); OC_Hook::connect('\\OC\\Files\\Cache\\Scanner', 'scan_folder', 'ScanListener', 'folder'); OC_Hook::connect('\\OC\\Files\\Cache\\Scanner', 'scan_file', 'ScanListener', 'file'); foreach ($users as $user) { $eventSource->send('user', $user); OC_Util::tearDownFS(); OC_Util::setupFS($user); $absolutePath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir); $mountPoints = \OC\Files\Filesystem::getMountPoints($absolutePath); $mountPoints[] = \OC\Files\Filesystem::getMountPoint($absolutePath); $mountPoints = array_reverse($mountPoints); //start with the mount point of $dir foreach ($mountPoints as $mountPoint) { $storage = \OC\Files\Filesystem::getStorage($mountPoint);
<?php set_time_limit(0); require_once '../../lib/base.php'; if (OC::checkUpgrade(false)) { $l = new \OC_L10N('core'); $eventSource = new OC_EventSource(); $updater = new \OC\Updater(\OC_Log::$object); $updater->listen('\OC\Updater', 'maintenanceStart', function () use ($eventSource, $l) { $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); }); $updater->listen('\OC\Updater', 'maintenanceEnd', function () use ($eventSource, $l) { $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); }); $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { $eventSource->send('success', (string)$l->t('Updated database')); }); $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { $eventSource->send('success', (string)$l->t('Checked database schema update')); }); $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); }); $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { $eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version))); }); $updater->listen('\OC\Updater', 'disabledApps', function ($appList) use ($eventSource, $l) { $list = array(); foreach ($appList as $appId) { $info = OC_App::getAppInfo($appId); $list[] = $info['name'] . ' (' . $info['id'] . ')';
<?php set_time_limit(0); $RUNTIME_NOAPPS = true; require_once '../../lib/base.php'; if (OC::checkUpgrade(false)) { $l = new \OC_L10N('core'); $eventSource = new OC_EventSource(); $updater = new \OC\Updater(\OC_Log::$object); $updater->listen('\\OC\\Updater', 'maintenanceStart', function () use($eventSource, $l) { $eventSource->send('success', (string) $l->t('Turned on maintenance mode')); }); $updater->listen('\\OC\\Updater', 'maintenanceEnd', function () use($eventSource, $l) { $eventSource->send('success', (string) $l->t('Turned off maintenance mode')); }); $updater->listen('\\OC\\Updater', 'dbUpgrade', function () use($eventSource, $l) { $eventSource->send('success', (string) $l->t('Updated database')); }); $updater->listen('\\OC\\Updater', 'filecacheStart', function () use($eventSource, $l) { $eventSource->send('success', (string) $l->t('Updating filecache, this may take really long...')); }); $updater->listen('\\OC\\Updater', 'filecacheDone', function () use($eventSource, $l) { $eventSource->send('success', (string) $l->t('Updated filecache')); }); $updater->listen('\\OC\\Updater', 'filecacheProgress', function ($out) use($eventSource, $l) { $eventSource->send('success', (string) $l->t('... %d%% done ...', array('percent' => $out))); }); $updater->listen('\\OC\\Updater', 'failure', function ($message) use($eventSource) { $eventSource->send('failure', $message); $eventSource->close(); OC_Config::setValue('maintenance', false);
public function done() { OC_Util::obEnd(); $this->eventSource->send('done', ''); $this->eventSource->close(); }