public function upgradePath($path)
 {
     $this->count++;
     if ($this->count > $this->lastSend + 5) {
         $this->lastSend = $this->count;
         $this->eventSource->send('count', $this->count);
     }
 }
Exemple #2
0
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();
}
Exemple #3
0
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();
}
 /**
  * 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;
 }
Exemple #5
0
}
//TODO why is stripslashes used on foldername in newfolder.php but not here?
$target = $dir . '/' . $filename;
if (\OC\Files\Filesystem::file_exists($target)) {
    $result['data'] = array('message' => $l10n->t('The name %s is already used in the folder %s. Please choose a different name.', array($filename, $dir)));
    OCP\JSON::error($result);
    exit;
}
if ($source) {
    $httpHelper = \OC::$server->getHTTPHelper();
    if (!$httpHelper->isHTTPURL($source)) {
        OCP\JSON::error(array('data' => array('message' => $l10n->t('Not a valid source'))));
        exit;
    }
    if (!ini_get('allow_url_fopen')) {
        $eventSource->send('error', $l10n->t('Server is not allowed to open URLs, please check the server configuration'));
        $eventSource->close();
        exit;
    }
    $source = $httpHelper->getFinalLocationOfURL($source);
    $ctx = stream_context_create(\OC::$server->getHTTPHelper()->getDefaultContextArray(), array('notification' => 'progress'));
    $sourceStream = @fopen($source, 'rb', false, $ctx);
    $result = 0;
    if (is_resource($sourceStream)) {
        $meta = stream_get_meta_data($sourceStream);
        if (isset($meta['wrapper_data']) && is_array($meta['wrapper_data'])) {
            //check stream size
            $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
            $freeSpace = $storageStats['freeSpace'];
            foreach ($meta['wrapper_data'] as $header) {
                if (strpos($header, ':') === false) {
Exemple #6
0
    $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))));
    } else {
        $eventSource->send('preview', array('image' => $imageName, 'preview' => (string) $preview->getPreview()));
    }
}
$eventSource->close();
    exit;
}
//TODO why is stripslashes used on foldername in newfolder.php but not here?
$target = $dir . '/' . $filename;
if (\OC\Files\Filesystem::file_exists($target)) {
    $result['data'] = array('message' => (string) $l10n->t('The name %s is already used in the folder %s. Please choose a different name.', array($filename, $dir)));
    OCP\JSON::error($result);
    exit;
}
if ($source) {
    if (substr($source, 0, 8) != 'https://' and substr($source, 0, 7) != 'http://') {
        OCP\JSON::error(array('data' => array('message' => $l10n->t('Not a valid source'))));
        exit;
    }
    if (!ini_get('allow_url_fopen')) {
        $eventSource->send('error', array('message' => $l10n->t('Server is not allowed to open URLs, please check the server configuration')));
        $eventSource->close();
        exit;
    }
    $ctx = stream_context_create(null, array('notification' => 'progress'));
    $sourceStream = @fopen($source, 'rb', false, $ctx);
    $result = 0;
    if (is_resource($sourceStream)) {
        $meta = stream_get_meta_data($sourceStream);
        if (isset($meta['wrapper_data']) && is_array($meta['wrapper_data'])) {
            //check stream size
            $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
            $freeSpace = $storageStats['freeSpace'];
            foreach ($meta['wrapper_data'] as $header) {
                list($name, $value) = explode(':', $header);
                if ('content-length' === strtolower(trim($name))) {
    OCP\JSON::error($result);
    exit;
}
if ($source) {
    if (substr($source, 0, 8) != 'https://' and substr($source, 0, 7) != 'http://') {
        OCP\JSON::error(array('data' => array('message' => $l10n->t('Not a valid source'))));
        exit;
    }
    $ctx = stream_context_create(null, array('notification' => 'progress'));
    $sourceStream = fopen($source, 'rb', false, $ctx);
    $result = \OC\Files\Filesystem::file_put_contents($target, $sourceStream);
    if ($result) {
        $meta = \OC\Files\Filesystem::getFileInfo($target);
        $mime = $meta['mimetype'];
        $id = $meta['fileid'];
        $eventSource->send('success', array('mime' => $mime, 'size' => \OC\Files\Filesystem::filesize($target), 'id' => $id, 'etag' => $meta['etag']));
    } else {
        $eventSource->send('error', $l10n->t('Error while downloading %s to %s', array($source, $target)));
    }
    $eventSource->close();
    exit;
} else {
    $success = false;
    if (!$content) {
        $templateManager = OC_Helper::getFileTemplateManager();
        $mimeType = OC_Helper::getMimetypeDetector()->detectPath($target);
        $content = $templateManager->getTemplate($mimeType);
    }
    if ($content) {
        $success = \OC\Files\Filesystem::file_put_contents($target, $content);
    } else {
Exemple #9
0
        return null;
    }
    return $folderid;
}
function importList($data, $parentid)
{
    $countsuccess = 0;
    foreach ($data as $collection) {
        if ($collection instanceof OCA\News\Feed) {
            $feedurl = $collection->getUrl();
            $feedtitle = $collection->getTitle();
            if (importFeed($feedurl, $parentid, $feedtitle)) {
                $countsuccess++;
            }
        } else {
            if ($collection instanceof OCA\News\Folder) {
                $folderid = importFolder($collection->getName(), $parentid);
                if ($folderid) {
                    $children = $collection->getChildren();
                    $countsuccess += importList($children, $folderid);
                }
            } else {
                OCP\Util::writeLog('news', 'ajax/importopml.php: Error importing OPML', OCP\Util::ERROR);
            }
        }
    }
    return $countsuccess;
}
$countsuccess = importList($data, 0);
$eventSource->send('success', array('data' => array('title' => $parsed->getTitle(), 'count' => $parsed->getCount(), 'countsuccess' => $countsuccess)));
$eventSource->close();
Exemple #10
0
 /**
  * @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();
 }
Exemple #11
0
}
if ($source) {
    if (substr($source, 0, 8) != 'https://' and substr($source, 0, 7) != 'http://') {
        OCP\JSON::error(array("data" => array("message" => "Not a valid source")));
        exit;
    }
    $ctx = stream_context_create(null, array('notification' => 'progress'));
    $sourceStream = fopen($source, 'rb', false, $ctx);
    $target = $dir . '/' . $filename;
    $result = OC_Filesystem::file_put_contents($target, $sourceStream);
    if ($result) {
        $target = OC_Filesystem::normalizePath($target);
        $meta = OC_FileCache::get($target);
        $mime = $meta['mimetype'];
        $id = OC_FileCache::getId($target);
        $eventSource->send('success', array('mime' => $mime, 'size' => OC_Filesystem::filesize($target), 'id' => $id));
    } else {
        $eventSource->send('error', "Error while downloading " . $source . ' to ' . $target);
    }
    $eventSource->close();
    exit;
} else {
    if ($content) {
        if (OC_Filesystem::file_put_contents($dir . '/' . $filename, $content)) {
            $meta = OC_FileCache::get($dir . '/' . $filename);
            $id = OC_FileCache::getId($dir . '/' . $filename);
            OCP\JSON::success(array("data" => array('content' => $content, 'id' => $id)));
            exit;
        }
    } elseif (OC_Files::newFile($dir, $filename, 'file')) {
        $meta = OC_FileCache::get($dir . '/' . $filename);
Exemple #12
0
 public function done()
 {
     $this->eventSource->send('done', $this->scannedCount);
 }
Exemple #13
0
$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
{
    private $fileCount = 0;
    private $lastCount = 0;
Exemple #14
0
 /**
  * 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);
 }
Exemple #15
0
    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);
        if ($storage) {
            ScanListener::$mountPoints[$storage->getId()] = $mountPoint;
            $scanner = $storage->getScanner();
            if ($force) {
                $scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG);
            } else {
<?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'] . ')';
Exemple #17
0
<?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);
Exemple #18
0
 public function done()
 {
     OC_Util::obEnd();
     $this->eventSource->send('done', '');
     $this->eventSource->close();
 }