Example #1
0
 /**
  * @param File $file
  * @return static
  */
 public static function fromFile(File $file)
 {
     $note = new static();
     $note->setId($file->getId());
     $note->setContent($file->getContent());
     $note->setModified($file->getMTime());
     $note->setTitle(substr($file->getName(), 0, -4));
     // remove trailing .txt
     $note->resetUpdatedFields();
     return $note;
 }
Example #2
0
 /**
  * @param File $file
  * @return static
  */
 public static function fromFile(File $file)
 {
     $note = new static();
     $note->setId($file->getId());
     $note->setContent($file->getContent());
     $note->setModified($file->getMTime());
     $note->setTitle(pathinfo($file->getName(), PATHINFO_FILENAME));
     // remove extension
     $note->resetUpdatedFields();
     return $note;
 }
Example #3
0
 /**
  * Get all shares by the given user. Sharetype and path can be used to filter.
  *
  * @param string $userId
  * @param int $shareType
  * @param \OCP\Files\File|\OCP\Files\Folder $node
  * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
  * @param int $limit The maximum number of shares to be returned, -1 for all shares
  * @param int $offset
  * @return Share[]
  */
 public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset)
 {
     $qb = $this->dbConn->getQueryBuilder();
     $qb->select('*')->from('share');
     $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType)));
     /**
      * Reshares for this user are shares where they are the owner.
      */
     if ($reshares === false) {
         //Special case for old shares created via the web UI
         $or1 = $qb->expr()->andX($qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), $qb->expr()->isNull('uid_initiator'));
         $qb->andWhere($qb->expr()->orX($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), $or1));
     } else {
         $qb->andWhere($qb->expr()->orX($qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))));
     }
     if ($node !== null) {
         $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
     }
     if ($limit !== -1) {
         $qb->setMaxResults($limit);
     }
     $qb->setFirstResult($offset);
     $qb->orderBy('id');
     $cursor = $qb->execute();
     $shares = [];
     while ($data = $cursor->fetch()) {
         $shares[] = $this->createShare($data);
     }
     $cursor->closeCursor();
     return $shares;
 }
Example #4
0
 /**
  * index a file
  *
  * @param File $file the file to be indexed
  * @param bool $commit
  *
  * @return bool true when something was stored in the index, false otherwise (eg, folders are not indexed)
  * @throws NotIndexedException when an unsupported file type is encountered
  */
 public function indexFile(File $file, $commit = true)
 {
     // we decide how to index on mime type or file extension
     $mimeType = $file->getMimeType();
     $fileExtension = strtolower(pathinfo($file->getName(), PATHINFO_EXTENSION));
     // initialize plain lucene document
     $doc = new Document();
     // index content for local files only
     $storage = $file->getStorage();
     if ($storage->isLocal()) {
         $path = $storage->getLocalFile($file->getInternalPath());
         //try to use special lucene document types
         if ('text/html' === $mimeType) {
             //TODO could be indexed, even if not local
             $doc = HTML::loadHTML($file->getContent());
         } else {
             if ('text/' === substr($mimeType, 0, 5) || 'application/x-tex' === $mimeType) {
                 $body = $file->getContent();
                 if ($body != '') {
                     $doc->addField(Document\Field::UnStored('body', $body));
                 }
             } else {
                 if ('application/pdf' === $mimeType) {
                     $doc = Pdf::loadPdf($file->getContent());
                     // the zend classes only understand docx and not doc files
                 } else {
                     if ($fileExtension === 'docx') {
                         $doc = Document\Docx::loadDocxFile($path);
                         //} else if ('application/msexcel' === $mimeType) {
                     } else {
                         if ($fileExtension === 'xlsx') {
                             $doc = Document\Xlsx::loadXlsxFile($path);
                             //} else if ('application/mspowerpoint' === $mimeType) {
                         } else {
                             if ($fileExtension === 'pptx') {
                                 $doc = Document\Pptx::loadPptxFile($path);
                             } else {
                                 if ($fileExtension === 'odt') {
                                     $doc = Odt::loadOdtFile($path);
                                 } else {
                                     if ($fileExtension === 'ods') {
                                         $doc = Ods::loadOdsFile($path);
                                     } else {
                                         throw new NotIndexedException();
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Store filecache id as unique id to lookup by when deleting
     $doc->addField(Document\Field::Keyword('fileId', $file->getId()));
     // Store document path for the search results
     $doc->addField(Document\Field::Text('path', $file->getPath(), 'UTF-8'));
     $doc->addField(Document\Field::unIndexed('mtime', $file->getMTime()));
     $doc->addField(Document\Field::unIndexed('size', $file->getSize()));
     $doc->addField(Document\Field::unIndexed('mimetype', $mimeType));
     $this->index->updateFile($doc, $file->getId(), $commit);
     return true;
 }