/** * 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)); }
public function testGetOldPaths() { $this->assertEmpty($this->storage->getOldPaths()); $this->storage->setPath('foo'); $this->assertEmpty($this->storage->getOldPaths()); $this->storage->setPath('bar'); $this->assertEquals(['foo'], $this->storage->getOldPaths()); $this->storage->setPath('baz'); $this->assertEquals(['foo', 'bar'], $this->storage->getOldPaths()); }
/** * @param array $types * * @return StorageEntity[] */ public function getList(array $types = []) { if (!$types || $types == StorageEntity::getTypes()) { return $this->getEntityManager()->createQuery(' SELECT s FROM AnimeDbCatalogBundle:Storage s ORDER BY s.id DESC ')->getResult(); } return $this->getEntityManager()->createQuery(' SELECT s FROM AnimeDbCatalogBundle:Storage s WHERE s.type IN (:types) ORDER BY s.id DESC ')->setParameter(':types', $types)->getResult(); }
/** * @param Storage $storage * * @return Item */ public function setStorage(Storage $storage) { $this->getItem()->setPath($storage->getPath() . 'Beck (2004) [TV]' . DIRECTORY_SEPARATOR); return parent::setStorage($storage); }
/** * 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; }
/** * @param Storage $storage * * @return Item */ public function setStorage(Storage $storage) { $this->getItem()->setPath($storage->getPath() . 'Fullmetal Alchemist (2003) [TV]' . DIRECTORY_SEPARATOR); return parent::setStorage($storage); }
/** * @param Storage $storage * * @return Item */ public function setStorage(Storage $storage) { $this->getItem()->setPath($storage->getPath() . 'Spirited Away (2001)' . DIRECTORY_SEPARATOR); return parent::setStorage($storage); }
/** * Add storage (Stap #2). * * @param Request $request * * @return Response */ public function addStorageAction(Request $request) { // app already installed if ($this->container->getParameter('anime_db.catalog.installed')) { return $this->redirect($this->generateUrl('home')); } $response = $this->getCacheTimeKeeper()->getResponse('AnimeDbCatalogBundle:Storage'); // response was not modified for this request if ($response->isNotModified($request)) { return $response; } // get last storage $storage = $this->getRepository()->getLast(); if (!$storage) { $storage = new Storage(); $storage->setPath(Filesystem::getUserHomeDir()); } $form = $this->createForm(new StorageForm(), $storage)->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($storage); $em->flush(); // redirect to step 3 return $this->redirect($this->generateUrl('install_what_you_want')); } return $this->render('AnimeDbCatalogBundle:Install:add_storage.html.twig', ['form' => $form->createView(), 'is_new' => !$storage->getId(), 'guide' => $this->get('anime_db.api.client')->getSiteUrl(StorageController::GUIDE_LINK)], $response); }
/** * 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]); }
/** * @param Storage $storage * * @return Item */ public function setStorage(Storage $storage) { $this->getItem()->setPath($storage->getPath() . 'Hellsing (2006) [OVA]' . DIRECTORY_SEPARATOR); return parent::setStorage($storage); }
/** * @param Storage $storage * * @return Item */ public function setStorage(Storage $storage) { $this->getItem()->setPath($storage->getPath() . 'Gintama (2006) [TV-1]' . DIRECTORY_SEPARATOR); return parent::setStorage($storage); }
/** * @param Storage $storage * * @return Item */ public function setStorage(Storage $storage) { $this->getItem()->setPath($storage->getPath() . 'Tengen Toppa Gurren Lagann (2007) [TV]' . DIRECTORY_SEPARATOR); return parent::setStorage($storage); }
/** * @param Storage $storage * * @return Item */ public function setStorage(Storage $storage) { $this->getItem()->setPath($storage->getPath() . 'Tonari no Totoro (1988)' . DIRECTORY_SEPARATOR); return parent::setStorage($storage); }
/** * @param Storage $storage * * @return Item */ public function setStorage(Storage $storage) { $this->getItem()->setPath($storage->getPath() . 'Samurai X - Trust Betrayal (1999) [OVA]' . DIRECTORY_SEPARATOR); return parent::setStorage($storage); }
/** * 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; }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('name', null, ['label' => 'Name'])->add('path', new LocalPathField(), ['label' => 'Path', 'required' => false, 'attr' => ['placeholder' => Filesystem::getUserHomeDir()]])->add('type', 'choice', ['choices' => StorageEntity::getTypeTitles(), 'label' => 'Type'])->add('description', null, ['label' => 'Description']); }