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(); }
/** * Add a mount point to the filesystem * @param string $mountPoint Mount point * @param string $class Backend class * @param array $classOptions Backend parameters for the class * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER * @param string $applicable User or group to apply mount to * @param bool $isPersonal Personal or system mount point i.e. is this being called from the personal or admin page * @param int|null $priority Mount point priority, null for default * @return boolean */ public static function addMountPoint($mountPoint, $class, $classOptions, $mountType, $applicable, $isPersonal = false, $priority = null) { $backends = self::getBackends(); $mountPoint = OC\Files\Filesystem::normalizePath($mountPoint); $relMountPoint = $mountPoint; if ($mountPoint === '' || $mountPoint === '/') { // can't mount at root folder return false; } if (!isset($backends[$class])) { // invalid backend return false; } if ($isPersonal) { // Verify that the mount point applies for the current user // Prevent non-admin users from mounting local storage and other disabled backends $allowed_backends = self::getPersonalBackends(); if ($applicable != OCP\User::getUser() || !isset($allowed_backends[$class])) { return false; } $mountPoint = '/' . $applicable . '/files/' . ltrim($mountPoint, '/'); } else { $mountPoint = '/$user/files/' . ltrim($mountPoint, '/'); } $mount = array($applicable => array($mountPoint => array('class' => $class, 'options' => self::encryptPasswords($classOptions)))); if (!$isPersonal && !is_null($priority)) { $mount[$applicable][$mountPoint]['priority'] = $priority; } $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL); // who else loves multi-dimensional array ? $isNew = !isset($mountPoints[$mountType]) || !isset($mountPoints[$mountType][$applicable]) || !isset($mountPoints[$mountType][$applicable][$mountPoint]); $mountPoints = self::mergeMountPoints($mountPoints, $mount, $mountType); // Set default priority if none set if (!isset($mountPoints[$mountType][$applicable][$mountPoint]['priority'])) { if (isset($backends[$class]['priority'])) { $mountPoints[$mountType][$applicable][$mountPoint]['priority'] = $backends[$class]['priority']; } else { $mountPoints[$mountType][$applicable][$mountPoint]['priority'] = 100; } } self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints); $result = self::getBackendStatus($class, $classOptions, $isPersonal); if ($result && $isNew) { \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create_mount, array(\OC\Files\Filesystem::signal_param_path => $relMountPoint, \OC\Files\Filesystem::signal_param_mount_type => $mountType, \OC\Files\Filesystem::signal_param_users => $applicable)); } return $result; }
public function testDefaultExpireDate() { \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1); // TODO drop this once all code paths use the DI version - otherwise // the cache inside this config object is out of date because // OC_Appconfig is used and bypasses this cache which lead to integrity // constraint violations $config = \OC::$server->getConfig(); $config->deleteAppValue('core', 'shareapi_default_expire_date'); $config->deleteAppValue('core', 'shareapi_enforce_expire_date'); $config->deleteAppValue('core', 'shareapi_expire_after_n_days'); $config->setAppValue('core', 'shareapi_default_expire_date', 'yes'); $config->setAppValue('core', 'shareapi_enforce_expire_date', 'yes'); $config->setAppValue('core', 'shareapi_expire_after_n_days', '2'); // default expire date is set to 2 days // the time when the share was created is set to 3 days in the past // user defined expire date is set to +2 days from now on // -> link should be already expired by the default expire date but the user // share should still exists. $now = time(); $dateFormat = 'Y-m-d H:i:s'; $shareCreated = $now - 3 * 24 * 60 * 60; $expireDate = date($dateFormat, $now + 2 * 24 * 60 * 60); $info = OC\Files\Filesystem::getFileInfo($this->filename); $this->assertTrue($info instanceof \OC\Files\FileInfo); $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); $this->assertTrue(is_string($result)); $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31); $this->assertTrue($result); $result = \OCP\Share::setExpirationDate('file', $info->getId(), $expireDate, $now); $this->assertTrue($result); //manipulate stime so that both shares are older then the default expire date $statement = "UPDATE `*PREFIX*share` SET `stime` = ? WHERE `share_type` = ?"; $query = \OCP\DB::prepare($statement); $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_LINK)); $this->assertSame(1, $result); $query = \OCP\DB::prepare($statement); $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_USER)); $this->assertSame(1, $result); // now the link share should expire because of enforced default expire date // the user share should still exist $result = \OCP\Share::getItemShared('file', $info->getId()); $this->assertTrue(is_array($result)); $this->assertSame(1, count($result)); $share = reset($result); $this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share['share_type']); //cleanup $result = \OCP\Share::unshare('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); $this->assertTrue($result); $config->setAppValue('core', 'shareapi_default_expire_date', 'no'); $config->setAppValue('core', 'shareapi_enforce_expire_date', 'no'); }
exit; } else { bailOut($l10n->t('Error uploading contacts to storage.')); } } // File input transfers are handled here if (!isset($_FILES['importfile'])) { OCP\Util::writeLog('contacts', 'ajax/uploadphoto.php: No file was uploaded. Unknown error.', OCP\Util::DEBUG); OCP\JSON::error(array(' data' => array('message' => 'No file was uploaded. Unknown error'))); exit; } $error = $_FILES['importfile']['error']; if ($error !== UPLOAD_ERR_OK) { $errors = array(0 => $l10n->t("There is no error, the file uploaded with success"), 1 => $l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini") . ini_get('upload_max_filesize'), 2 => $l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"), 3 => $l10n->t("The uploaded file was only partially uploaded"), 4 => $l10n->t("No file was uploaded"), 6 => $l10n->t("Missing a temporary folder")); bailOut($errors[$error]); } $file = $_FILES['importfile']; if (file_exists($file['tmp_name'])) { $filename = strtr($file['name'], array('/' => '', "\\" => '')); if (OC\Files\Filesystem::isFileBlacklisted($filename)) { bailOut($l10n->t('Upload of blacklisted file:') . $filename); } if ($view->file_put_contents('/imports/' . $filename, file_get_contents($file['tmp_name']))) { OCP\JSON::success(array('data' => array('file' => $filename, 'name' => $filename))); } else { bailOut($l10n->t('Error uploading contacts to storage.')); } } else { bailOut('Temporary file: \'' . $file['tmp_name'] . '\' has gone AWOL?'); }
/** * Add a mount point to the filesystem * @param string Mount point * @param string Backend class * @param array Backend parameters for the class * @param string MOUNT_TYPE_GROUP | MOUNT_TYPE_USER * @param string User or group to apply mount to * @param bool Personal or system mount point i.e. is this being called from the personal or admin page * @return bool */ public static function addMountPoint($mountPoint, $class, $classOptions, $mountType, $applicable, $isPersonal = false) { $backends = self::getBackends(); $mountPoint = OC\Files\Filesystem::normalizePath($mountPoint); if ($mountPoint === '' || $mountPoint === '/' || $mountPoint == '/Shared') { // can't mount at root or "Shared" folder return false; } if (!isset($backends[$class])) { // invalid backend return false; } if ($isPersonal) { // Verify that the mount point applies for the current user // Prevent non-admin users from mounting local storage if ($applicable !== OCP\User::getUser() || strtolower($class) === '\\oc\\files\\storage\\local') { return false; } $mountPoint = '/' . $applicable . '/files/' . ltrim($mountPoint, '/'); } else { $mountPoint = '/$user/files/' . ltrim($mountPoint, '/'); } $mount = array($applicable => array($mountPoint => array('class' => $class, 'options' => self::encryptPasswords($classOptions)))); $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL); // Merge the new mount point into the current mount points if (isset($mountPoints[$mountType])) { if (isset($mountPoints[$mountType][$applicable])) { $mountPoints[$mountType][$applicable] = array_merge($mountPoints[$mountType][$applicable], $mount[$applicable]); } else { $mountPoints[$mountType] = array_merge($mountPoints[$mountType], $mount); } } else { $mountPoints[$mountType] = $mount; } self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints); return self::getBackendStatus($class, $classOptions); }
/** * Add a mount point to the filesystem * * @param string $mountPoint Mount point * @param string $class Backend class * @param array $classOptions Backend parameters for the class * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER * @param string $applicable User or group to apply mount to * @param bool $isPersonal Personal or system mount point i.e. is this being called from the personal or admin page * @param int|null $priority Mount point priority, null for default * @return boolean */ public static function addMountPoint($mountPoint, $class, $classOptions, $mountType, $applicable, $isPersonal = false, $priority = null) { $backends = self::getBackends(); $mountPoint = OC\Files\Filesystem::normalizePath($mountPoint); $relMountPoint = $mountPoint; if ($mountPoint === '' || $mountPoint === '/') { // can't mount at root folder return false; } if (!isset($backends[$class])) { // invalid backend return false; } if ($isPersonal) { // Verify that the mount point applies for the current user // Prevent non-admin users from mounting local storage and other disabled backends $allowed_backends = self::getPersonalBackends(); if ($applicable != OCP\User::getUser() || !isset($allowed_backends[$class])) { return false; } $mountPoint = '/' . $applicable . '/files/' . ltrim($mountPoint, '/'); } else { $mountPoint = '/$user/files/' . ltrim($mountPoint, '/'); //��moutPoint����Ҫ����� } //$mount数组,用于存到数据库 $mount = array($applicable => array($mountPoint => array('class' => $class, 'options' => self::encryptPasswords($classOptions), 'priority' => 100))); //给$mount赋值storage_id self::addStorageId($mount[$applicable][$mountPoint]); //获取mount的数据库对象 $mountdatabase = new \OC\Files\Mount\MountDatabase(); $res = $mountdatabase->getMountPointByUserAndStorage($applicable, $mountPoint); //判断是否数据库已经存在,存在则返回true if (!empty($res)) { return '已经存在改数据!'; } else { //不存在则添加后返回true $flag = $mountdatabase->insertMountPoint($mount); /*if (!$isPersonal && !is_null($priority)) { $mount[$applicable][$mountPoint]['priority'] = $priority; } $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : null); // who else loves multi-dimensional array ? $isNew = !isset($mountPoints[$mountType]) || !isset($mountPoints[$mountType][$applicable]) || !isset($mountPoints[$mountType][$applicable][$mountPoint]); $mountPoints = self::mergeMountPoints($mountPoints, $mount, $mountType); // Set default priority if none set if (!isset($mountPoints[$mountType][$applicable][$mountPoint]['priority'])) { if (isset($backends[$class]['priority'])) { $mountPoints[$mountType][$applicable][$mountPoint]['priority'] = $backends[$class]['priority']; } else { $mountPoints[$mountType][$applicable][$mountPoint]['priority'] = 100; } } self::writeData($isPersonal ? OCP\User::getUser() : null, $mountPoints);*/ $result = self::getBackendStatus($class, $classOptions, $isPersonal); if ($result && $flag) { \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create_mount, array(\OC\Files\Filesystem::signal_param_path => $relMountPoint, \OC\Files\Filesystem::signal_param_mount_type => $mountType, \OC\Files\Filesystem::signal_param_users => $applicable)); } //return $result; return '新增数据成功!'; } }
$nl = "\n"; global $progresskey; $progresskey = 'contacts.import-' . (isset($_GET['progresskey']) ? $_GET['progresskey'] : ''); if (isset($_GET['progress']) && $_GET['progress']) { echo OC_Cache::get($progresskey); die; } function writeProgress($pct) { global $progresskey; OC_Cache::set($progresskey, $pct, 300); } writeProgress('10'); $view = null; $inputfile = strtr($_POST['file'], array('/' => '', "\\" => '')); if (OC\Files\Filesystem::isFileBlacklisted($inputfile)) { OCP\JSON::error(array('data' => array('message' => 'Upload of blacklisted file: ' . $inputfile))); exit; } if (isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') { $view = OCP\Files::getStorage('contacts'); $file = $view->file_get_contents('/imports/' . $inputfile); } else { $file = \OC\Files\Filesystem::file_get_contents($_POST['path'] . '/' . $inputfile); } if (!$file) { OCP\JSON::error(array('data' => array('message' => 'Import file was empty.'))); exit; } if (isset($_POST['method']) && $_POST['method'] == 'new') { $id = OCA\Contacts\Addressbook::add(OCP\USER::getUser(), $_POST['addressbookname']);