Ejemplo n.º 1
0
 protected function main()
 {
     $this->init();
     $query = $this->input->getArgument('query');
     if ($this->input->getOption('md5')) {
         $nodes = Node::loadByMd5($query);
     } else {
         $nodes = Node::searchNodesByName($query);
     }
     $sort = Command::SORT_BY_NAME;
     if ($this->input->getOption('time')) {
         $sort = Command::SORT_BY_TIME;
     }
     $this->listNodes($nodes, $sort);
 }
Ejemplo n.º 2
0
 /**
  * Determine if a node matching the given path exists remotely. If a local
  * path is given, the MD5 will be compared as well.
  *
  * @param string      $remotePath The remote path to check
  * @param null|string $localPath  Local path of file to compare MD5
  *
  * @return array
  * @throws \Exception'
  */
 public function nodeExists($remotePath, $localPath = null)
 {
     if (is_null($file = Node::loadByPath($remotePath))) {
         if (!is_null($localPath)) {
             if (!empty($nodes = Node::loadByMd5(md5_file($localPath)))) {
                 $ids = [];
                 foreach ($nodes as $node) {
                     $ids[] = $node['id'];
                 }
                 return ['success' => true, 'data' => ['message' => "File(s) with same MD5: " . implode(', ', $ids), 'path_match' => false, 'md5_match' => true, 'nodes' => $nodes]];
             }
         }
         return ['success' => false, 'data' => ['message' => "File {$remotePath} does not exist.", 'path_match' => false, 'md5_match' => false]];
     }
     $retval = ['success' => true, 'data' => ['message' => "File {$remotePath} exists.", 'path_match' => true, 'md5_match' => false, 'node' => $file]];
     if (!is_null($localPath)) {
         if (!is_null($file['contentProperties']['md5'])) {
             if (md5_file($localPath) !== $file['contentProperties']['md5']) {
                 $retval['data']['message'] = "File {$remotePath} exists but does not match local checksum.";
             } else {
                 $retval['data']['message'] = "File {$remotePath} exists and is identical to local copy.";
                 $retval['data']['md5_match'] = true;
             }
         } else {
             $retval['data']['message'] = "File {$remotePath} exists but no checksum is available.";
         }
     }
     return $retval;
 }