Пример #1
0
 /**
  * Scan storage in background and export progress and output.
  *
  * @param StorageEntity $storage
  */
 public function export(StorageEntity $storage)
 {
     $output = sprintf($this->output, $storage->getId());
     $progress = sprintf($this->progress, $storage->getId());
     $this->fs->mkdir([dirname($output), dirname($progress)], 0755);
     $this->command->send(sprintf('php app/console animedb:scan-storage --no-ansi --force --export=%s %s >%s 2>&1', $progress, $storage->getId(), $output));
 }
 /**
  * Update storage id.
  *
  * @param string $path
  * @param Storage $storage
  * @param StorageRepository $rep
  *
  * @return Storage|bool
  */
 protected function checkStorageId($path, Storage $storage, StorageRepository $rep)
 {
     if (!file_exists($path . StorageListener::ID_FILE)) {
         // path is free. reserve for me
         file_put_contents($path . StorageListener::ID_FILE, $storage->getId());
     } elseif (file_get_contents($path . StorageListener::ID_FILE) == $storage->getId()) {
         // it is my path. do nothing
     } elseif (!($duplicate = $rep->find(file_get_contents($path . StorageListener::ID_FILE)))) {
         // this path is reserved storage that was removed and now this path is free
         file_put_contents($path . StorageListener::ID_FILE, $storage->getId());
     } else {
         return $duplicate;
     }
     return true;
 }
Пример #3
0
 /**
  * Get storage scan progress.
  *
  * @param Storage $storage
  *
  * @return JsonResponse
  */
 public function scanProgressAction(Storage $storage)
 {
     $filename = $this->container->getParameter('anime_db.catalog.storage.scan_progress');
     $filename = sprintf($filename, $storage->getId());
     if (!file_exists($filename)) {
         throw $this->createNotFoundException('The progress status cannot be read');
     }
     $log = trim(file_get_contents($filename), " \r\n%");
     return new JsonResponse(['status' => $log != '' ? intval($log) : 100]);
 }
Пример #4
0
 /**
  * Freeze item.
  *
  * @param Registry $doctrine
  *
  * @return Item
  */
 public function freez(Registry $doctrine)
 {
     $em = $doctrine->getManager();
     // create reference to existing entity
     if ($this->country) {
         $this->country = $em->getReference(get_class($this->country), $this->country->getId());
     }
     if ($this->storage) {
         $this->storage = $em->getReference(get_class($this->storage), $this->storage->getId());
     }
     $this->type = $em->getReference(get_class($this->type), $this->type->getId());
     foreach ($this->genres as $key => $genre) {
         $this->genres[$key] = $em->getReference(get_class($genre), $genre->getId());
     }
     return $this;
 }