/**
  * Background scanner main job
  * @return null
  */
 public function run()
 {
     if (!$this->initFS()) {
         return;
     }
     // locate files that are not checked yet
     $dirMimetypeId = \OC::$server->getMimeTypeLoader()->getId('httpd/unix-directory');
     $sql = 'SELECT `*PREFIX*filecache`.`fileid`, `*PREFIX*storages`.*' . ' FROM `*PREFIX*filecache`' . ' LEFT JOIN `*PREFIX*files_antivirus` ON `*PREFIX*files_antivirus`.`fileid` = `*PREFIX*filecache`.`fileid`' . ' JOIN `*PREFIX*storages` ON `*PREFIX*storages`.`numeric_id` = `*PREFIX*filecache`.`storage`' . ' WHERE `mimetype` != ?' . ' AND (`*PREFIX*storages`.`id` LIKE ? OR `*PREFIX*storages`.`id` LIKE ?)' . ' AND (`*PREFIX*files_antivirus`.`fileid` IS NULL OR `mtime` > `check_time`)' . ' AND `path` LIKE ?';
     $stmt = \OCP\DB::prepare($sql, 5);
     try {
         $result = $stmt->execute(array($dirMimetypeId, 'local::%', 'home::%', 'files/%'));
         if (\OCP\DB::isError($result)) {
             \OCP\Util::writeLog('files_antivirus', __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
             return;
         }
     } catch (\Exception $e) {
         \OCP\Util::writeLog('files_antivirus', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
         return;
     }
     $view = new \OC\Files\View('/');
     while ($row = $result->fetchRow()) {
         $path = $view->getPath($row['fileid']);
         if (!is_null($path)) {
             $item = new Item($this->l10n, $view, $path, $row['fileid']);
             $scanner = $this->scannerFactory->getScanner();
             $status = $scanner->scan($item);
             $status->dispatch($item, true);
         }
     }
     \OC_Util::tearDownFS();
 }
 protected function shareFileOrFolderWithGroup($params)
 {
     // User performing the share
     $subject = 'shared_sharing_group_self';
     $this->shareNotificationForSharer($subject, $params['shareWith'], $params['fileSource'], $params['itemType']);
     // Members of the new group
     $affectedUsers = array();
     $usersInGroup = Data::readGroupUsers($params['shareWith']);
     foreach ($usersInGroup as $user) {
         $affectedUsers[$user] = $params['fileTarget'];
     }
     // Remove the triggering user, we already managed his notifications
     unset($affectedUsers[$this->currentUser]);
     if (empty($affectedUsers)) {
         return;
     }
     $filteredStreamUsersInGroup = $this->userSettings->filterUsersBySetting($usersInGroup, 'stream', Files_Sharing::TYPE_SHARED);
     $filteredEmailUsersInGroup = $this->userSettings->filterUsersBySetting($usersInGroup, 'email', Files_Sharing::TYPE_SHARED);
     // Check when there was a naming conflict and the target is different
     // for some of the users
     $query = DB::prepare('SELECT `share_with`, `file_target` FROM `*PREFIX*share` WHERE `parent` = ? ');
     $result = $query->execute(array($params['id']));
     if (DB::isError($result)) {
         Util::writeLog('OCA\\Activity\\Hooks::shareFileOrFolderWithGroup', DB::getErrorMessage($result), Util::ERROR);
     } else {
         while ($row = $result->fetchRow()) {
             $affectedUsers[$row['share_with']] = $row['file_target'];
         }
     }
     foreach ($affectedUsers as $user => $path) {
         if (empty($filteredStreamUsersInGroup[$user]) && empty($filteredEmailUsersInGroup[$user])) {
             continue;
         }
         $this->addNotificationsForUser($user, 'shared_with_by', array($path, $this->currentUser), $path, $params['itemType'] === 'file', !empty($filteredStreamUsersInGroup[$user]), !empty($filteredEmailUsersInGroup[$user]) ? $filteredEmailUsersInGroup[$user] : 0);
     }
 }
Example #3
0
 /**
  * @brief Move card(s) to an address book
  * @param integer $aid Address book id
  * @param $id Array or integer of cards to be moved.
  * @return boolean
  *
  */
 public static function moveToAddressBook($aid, $id, $isAddressbook = false)
 {
     $addressbook = Addressbook::find($aid);
     if ($addressbook['userid'] != \OCP\User::getUser()) {
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $aid);
         if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE)) {
             throw new \Exception(App::$l10n->t('You don\'t have permissions to move contacts into this address book'));
         }
     }
     if (is_array($id)) {
         // NOTE: This block is currently not used and need rewrite if used!
         foreach ($id as $index => $cardId) {
             $card = self::find($cardId);
             if (!$card) {
                 unset($id[$index]);
             }
             $oldAddressbook = Addressbook::find($card['addressbookid']);
             if ($oldAddressbook['userid'] != \OCP\User::getUser()) {
                 $sharedContact = \OCP\Share::getItemSharedWithBySource(App::SHARECONTACT, App::SHARECONTACTPREFIX . $cardId, \OCP\Share::FORMAT_NONE, null, true);
                 if (!$sharedContact || !($sharedContact['permissions'] & \OCP\PERMISSION_DELETE)) {
                     unset($id[$index]);
                 }
             }
         }
         $id_sql = join(',', array_fill(0, count($id), '?'));
         $prep = 'UPDATE `' . App::ContactsTable . '` SET `addressbookid` = ? WHERE `id` IN (' . $id_sql . ')';
         try {
             $stmt = \OCP\DB::prepare($prep);
             //$aid = array($aid);
             $vals = array_merge((array) $aid, $id);
             $result = $stmt->execute($vals);
             if (\OCP\DB::isError($result)) {
                 \OCP\Util::writeLog(App::$appname, __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
                 throw new \Exception(App::$l10n->t('Database error during move.'));
             }
         } catch (\Exception $e) {
             \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
             \OCP\Util::writeLog(App::$appname, __METHOD__ . ', ids: ' . join(',', $vals), \OCP\Util::DEBUG);
             \OCP\Util::writeLog(App::$appname, __METHOD__ . ', SQL:' . $prep, \OCP\Util::DEBUG);
             throw new \Exception(App::$l10n->t('Database error during move.'));
         }
     } else {
         $stmt = null;
         if ($isAddressbook) {
             $stmt = \OCP\DB::prepare('UPDATE `' . App::ContactsTable . '` SET `addressbookid` = ? WHERE `addressbookid` = ?');
         } else {
             $card = self::find($id);
             if (!$card) {
                 throw new \Exception(App::$l10n->t('Error finding card to move.'));
             }
             $oldAddressbook = Addressbook::find($card['addressbookid']);
             if ($oldAddressbook['userid'] != \OCP\User::getUser()) {
                 $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $oldAddressbook['id']);
                 if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE)) {
                     throw new \Exception(App::$l10n->t('You don\'t have permissions to move contacts from this address book'));
                 }
             }
             Addressbook::touch($oldAddressbook['id']);
             $stmt = \OCP\DB::prepare('UPDATE `' . App::ContactsTable . '` SET `addressbookid` = ? WHERE `id` = ?');
         }
         try {
             $result = $stmt->execute(array($aid, $id));
             if (\OCP\DB::isError($result)) {
                 \OCP\Util::writeLog(App::$appname, __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
                 throw new \Exception(App::$l10n->t('Database error during move.'));
             }
         } catch (\Exception $e) {
             \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::DEBUG);
             \OCP\Util::writeLog(App::$appname, __METHOD__ . ' id: ' . $id, \OCP\Util::DEBUG);
             throw new \Exception(App::$l10n->t('Database error during move.'));
         }
     }
     //\OC_Hook::emit('\OCA\Contacts\VCard', 'post_moveToAddressbook', array('aid' => $aid, 'id' => $id));
     Addressbook::touch($aid);
     return true;
 }
Example #4
0
 /**
  * Delete all entries we dealt with
  *
  * @param array $affectedUsers
  * @param int $maxTime
  */
 public function deleteSentItems($affectedUsers, $maxTime)
 {
     $placeholders = implode(',', array_fill(0, sizeof($affectedUsers), '?'));
     $queryParams = $affectedUsers;
     array_unshift($queryParams, (int) $maxTime);
     $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*activity_mq` ' . ' WHERE `amq_timestamp` <= ? ' . ' AND `amq_affecteduser` IN (' . $placeholders . ')');
     $result = $query->execute($queryParams);
     if (\OCP\DB::isError($result)) {
         \OCP\Util::writeLog('Activity', \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
     }
 }
Example #5
0
 public static function updateDBProperties($contactid, $vcard = null)
 {
     $stmt = \OCP\DB::prepare('DELETE FROM `' . self::ContactsProbTable . '` WHERE `contactid` = ?');
     try {
         $stmt->execute(array($contactid));
     } catch (\Exception $e) {
         \OCP\Util::writeLog(self::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
         \OCP\Util::writeLog(self::$appname, __METHOD__ . ', id: ' . $id, \OCP\Util::DEBUG);
         throw new \Exception(App::$l10n->t('There was an error deleting properties for this contact.'));
     }
     if (is_null($vcard)) {
         return;
     }
     $stmt = \OCP\DB::prepare('INSERT INTO `' . self::ContactsProbTable . '` ' . '(`userid`, `contactid`,`name`,`value`,`preferred`) VALUES(?,?,?,?,?)');
     foreach ($vcard->children as $property) {
         if (!in_array($property->name, self::$index_properties)) {
             continue;
         }
         $preferred = 0;
         foreach ($property->parameters as $parameter) {
             if ($parameter->name == 'TYPE' && strtoupper($parameter->getValue()) == 'PREF') {
                 $preferred = 1;
                 break;
             }
         }
         try {
             $result = $stmt->execute(array(\OCP\User::getUser(), $contactid, $property->name, $property->getValue(), $preferred));
             if (\OCP\DB::isError($result)) {
                 \OCP\Util::writeLog(self::$appname, __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
                 return false;
             }
         } catch (\Exception $e) {
             \OCP\Util::writeLog(self::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
             return false;
         }
     }
 }
Example #6
0
 /**
  * Delete tags from the database.
  *
  * @param string[]|integer[] $names An array of tags (names or IDs) to delete
  * @return bool Returns false on error
  */
 public function delete($names)
 {
     if (!is_array($names)) {
         $names = array($names);
     }
     $names = array_map('trim', $names);
     array_filter($names);
     \OCP\Util::writeLog('core', __METHOD__ . ', before: ' . print_r($this->tags, true), \OCP\Util::DEBUG);
     foreach ($names as $name) {
         $id = null;
         if (is_numeric($name)) {
             $key = $this->getTagById($name);
         } else {
             $key = $this->getTagByName($name);
         }
         if ($key !== false) {
             $tag = $this->tags[$key];
             $id = $tag->getId();
             unset($this->tags[$key]);
             $this->mapper->delete($tag);
         } else {
             \OCP\Util::writeLog('core', __METHOD__ . 'Cannot delete tag ' . $name . ': not found.', \OCP\Util::ERROR);
         }
         if (!is_null($id) && $id !== false) {
             try {
                 $sql = 'DELETE FROM `' . self::RELATION_TABLE . '` ' . 'WHERE `categoryid` = ?';
                 $stmt = \OCP\DB::prepare($sql);
                 $result = $stmt->execute(array($id));
                 if (\OCP\DB::isError($result)) {
                     \OCP\Util::writeLog('core', __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
                     return false;
                 }
             } catch (\Exception $e) {
                 \OCP\Util::writeLog('core', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
                 return false;
             }
         }
     }
     return true;
 }
Example #7
0
 /**
  * get some information from a given share
  * @param int $shareID
  * @return array with: item_source, share_type, share_with, item_type, permissions
  */
 private static function getShareFromId($shareID)
 {
     $sql = 'SELECT `file_source`, `item_source`, `share_type`, `share_with`, `item_type`, `permissions`, `stime` FROM `*PREFIX*share` WHERE `id` = ?';
     $args = array($shareID);
     $query = \OCP\DB::prepare($sql);
     $result = $query->execute($args);
     if (\OCP\DB::isError($result)) {
         \OCP\Util::writeLog('files_sharing', \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
         return null;
     }
     if ($share = $result->fetchRow()) {
         return $share;
     }
     return null;
 }
Example #8
0
     $filesById[$file['fileid']] = $file;
 }
 try {
     $conn = \OC_DB::getConnection();
     $chunks = array_chunk(array_keys($filesById), 900, false);
     foreach ($chunks as $chunk) {
         $result = $conn->executeQuery('SELECT `category`, `categoryid`, `objid` ' . 'FROM `' . '*PREFIX*vcategory_to_object' . '` r, `' . '*PREFIX*vcategory' . '` ' . 'WHERE `categoryid` = `id` AND `uid` = ? AND r.`type` = ? AND `objid` IN (?)', array($_SESSION['user_id'], 'files', $chunk), array(null, null, \Doctrine\DBAL\Connection::PARAM_INT_ARRAY));
         while ($row = $result->fetch()) {
             $objId = (int) $row['objid'];
             if (!isset($entries[$objId])) {
                 $entry = $entries[$objId] = array();
             }
             $entry = $entries[$objId][] = $row['category'];
         }
         if (\OCP\DB::isError($result)) {
             \OCP\Util::writeLog('filefilter', __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
             return false;
         }
     }
 } catch (\Exception $e) {
     \OCP\Util::writeLog('filefilter', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
     return false;
 }
 //将tags赋值给files数组
 if (isset($entries)) {
     foreach ($entries as $fileId => $fileTags) {
         $filesById[$fileId]['tags'] = $fileTags;
     }
 }
 //将最后值变为filelist
 foreach ($filesById as $val) {
Example #9
0
 /**
  * Process the result and return the activities
  *
  * @param \OC_DB_StatementWrapper|int $result
  * @param \OCA\Activity\GroupHelper $groupHelper
  * @return array
  */
 public function getActivitiesFromQueryResult($result, GroupHelper $groupHelper)
 {
     if (DB::isError($result)) {
         Util::writeLog('Activity', DB::getErrorMessage($result), Util::ERROR);
     } else {
         while ($row = $result->fetchRow()) {
             $groupHelper->addActivity($row);
         }
     }
     return $groupHelper->getActivities();
 }
 private static function getSharingQueryResult($result)
 {
     $data = [];
     if (DB::isError($result)) {
         Util::writeLog('SharingGroup', DB::getErrorMessage($result), Util::ERROR);
         return;
     }
     while ($row = $result->fetchRow()) {
         $share = array('id' => $row['id']);
         array_push($data, $share);
     }
     return $data;
 }
Example #11
0
    /**
     * get the list of all unindexed files for the user
     *
     * @return array
     */
    public static function getUnindexed()
    {
        $files = array();
        $absoluteRoot = Filesystem::getView()->getAbsolutePath('/');
        $mounts = Filesystem::getMountPoints($absoluteRoot);
        $mount = Filesystem::getMountPoint($absoluteRoot);
        if (!in_array($mount, $mounts)) {
            $mounts[] = $mount;
        }
        $query = \OCP\DB::prepare('
			SELECT `*PREFIX*filecache`.`fileid`
			FROM `*PREFIX*filecache`
			LEFT JOIN `*PREFIX*lucene_status`
			ON `*PREFIX*filecache`.`fileid` = `*PREFIX*lucene_status`.`fileid`
			WHERE `storage` = ?
			AND `status` IS NULL OR `status` = ?
		');
        foreach ($mounts as $mount) {
            if (is_string($mount)) {
                $storage = Filesystem::getStorage($mount);
            } else {
                if ($mount instanceof \OC\Files\Mount\Mount) {
                    $storage = $mount->getStorage();
                } else {
                    $storage = null;
                    Util::writeLog('search_lucene', 'expected string or instance of \\OC\\Files\\Mount\\Mount got ' . json_encode($mount), Util::DEBUG);
                }
            }
            //only index local files for now
            if ($storage instanceof \OC\Files\Storage\Local) {
                $cache = $storage->getCache();
                $numericId = $cache->getNumericStorageId();
                $result = $query->execute(array($numericId, 'N'));
                if (\OCP\DB::isError($result)) {
                    Util::writeLog('search_lucene', 'failed to find unindexed files: ' . \OCP\DB::getErrorMessage($result), Util::WARN);
                    return false;
                }
                while ($row = $result->fetchRow()) {
                    $files[] = $row['fileid'];
                }
            }
        }
        return $files;
    }
Example #12
0
 /**
  * @brief Checks if an addressbook is active.
  * @param integer $id ID of the address book.
  * @return boolean
  */
 public static function isActive($id)
 {
     $sql = 'SELECT `active` FROM `' . App::AddrBookTable . '` WHERE `id` = ?';
     try {
         $stmt = \OCP\DB::prepare($sql);
         $result = $stmt->execute(array($id));
         if (\OCP\DB::isError($result)) {
             \OCP\Util::writeLog(App::$appname, __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
             return false;
         }
         $row = $result->fetchRow();
         return (bool) $row['active'];
     } catch (\Exception $e) {
         \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
 }
Example #13
0
 /**
  * Delete tags from the
  *
  * @param string[] $names An array of tags to delete
  * @return bool Returns false on error
  */
 public function delete($names)
 {
     if (!is_array($names)) {
         $names = array($names);
     }
     $names = array_map('trim', $names);
     array_filter($names);
     \OCP\Util::writeLog('core', __METHOD__ . ', before: ' . print_r($this->tags, true), \OCP\Util::DEBUG);
     foreach ($names as $name) {
         $id = null;
         if ($this->hasTag($name)) {
             $id = $this->array_searchi($name, $this->tags);
             unset($this->tags[$id]);
         }
         try {
             $stmt = \OCP\DB::prepare('DELETE FROM `' . self::TAG_TABLE . '` WHERE ' . '`uid` = ? AND `type` = ? AND `category` = ?');
             $result = $stmt->execute(array($this->user, $this->type, $name));
             if (\OCP\DB::isError($result)) {
                 \OCP\Util::writeLog('core', __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
             }
         } catch (\Exception $e) {
             \OCP\Util::writeLog('core', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
             return false;
         }
         if (!is_null($id) && $id !== false) {
             try {
                 $sql = 'DELETE FROM `' . self::RELATION_TABLE . '` ' . 'WHERE `categoryid` = ?';
                 $stmt = \OCP\DB::prepare($sql);
                 $result = $stmt->execute(array($id));
                 if (\OCP\DB::isError($result)) {
                     \OCP\Util::writeLog('core', __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
                     return false;
                 }
             } catch (\Exception $e) {
                 \OCP\Util::writeLog('core', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
                 return false;
             }
         }
     }
     return true;
 }
Example #14
0
 /**
  * Action to take if this item status is not infected
  * @param Status $status
  * @param boolean $isBackground
  */
 public function processClean(Status $status, $isBackground)
 {
     if (!$isBackground) {
         return;
     }
     try {
         $stmt = \OCP\DB::prepare('DELETE FROM `*PREFIX*files_antivirus` WHERE `fileid` = ?');
         $result = $stmt->execute(array($this->id));
         if (\OCP\DB::isError($result)) {
             //TODO: Use logger
             $this->logError(__METHOD__ . ', DB error: ' . \OCP\DB::getErrorMessage($result));
         }
         $stmt = \OCP\DB::prepare('INSERT INTO `*PREFIX*files_antivirus` (`fileid`, `check_time`) VALUES (?, ?)');
         $result = $stmt->execute(array($this->id, time()));
         if (\OCP\DB::isError($result)) {
             $this->logError(__METHOD__ . ', DB error: ' . \OCP\DB::getErrorMessage($result));
         }
     } catch (\Exception $e) {
         \OCP\Util::writeLog('files_antivirus', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
     }
 }