예제 #1
0
 public function createOneCollection()
 {
     $databoxes = self::$DI['app']['phraseanet.appbox']->get_databoxes();
     $collection = \collection::create(self::$DI['app'], array_shift($databoxes), self::$DI['app']['phraseanet.appbox'], 'TESTTODELETE');
     self::$createdCollections[] = $collection;
     return $collection;
 }
예제 #2
0
 public function bootTestCase()
 {
     $application = self::$DI['app'];
     if (!self::$object) {
         if (0 === count($databoxes = self::$DI['app']['phraseanet.appbox']->get_databoxes())) {
             $this->fail('No databox found for collection test');
         }
         $databox = array_shift($databoxes);
         self::$object = collection::create(self::$DI['app'], $databox, self::$DI['app']['phraseanet.appbox'], 'test_collection', self::$DI['user']);
         self::$objectDisable = collection::create(self::$DI['app'], $databox, self::$DI['app']['phraseanet.appbox'], 'test_collection', self::$DI['user']);
         self::$objectDisable->disable(self::$DI['app']['phraseanet.appbox']);
     }
 }
예제 #3
0
 public function setUp()
 {
     parent::setup();
     if (!self::$object) {
         if (0 === count($databoxes = self::$DI['app']->getDataboxes())) {
             $this->fail('No databox found for collection test');
         }
         $databox = array_shift($databoxes);
         self::$object = collection::create(self::$DI['app'], $databox, self::$DI['app']['phraseanet.appbox'], 'test_collection', self::$DI['user']);
         self::$objectDisable = collection::create(self::$DI['app'], $databox, self::$DI['app']['phraseanet.appbox'], 'test_collection', self::$DI['user']);
         self::$objectDisable->disable(self::$DI['app']['phraseanet.appbox']);
     }
 }
예제 #4
0
 private function createDB(Connection $dbConn = null, $template)
 {
     $template = new \SplFileInfo(__DIR__ . '/../../../conf.d/data_templates/' . $template . '-simple.xml');
     $databox = \databox::create($this->app, $dbConn, $template);
     $this->app['acl']->get($this->app['authentication']->getUser())->give_access_to_sbas([$databox->get_sbas_id()])->update_rights_to_sbas($databox->get_sbas_id(), ['bas_manage' => 1, 'bas_modify_struct' => 1, 'bas_modif_th' => 1, 'bas_chupub' => 1]);
     $collection = \collection::create($this->app, $databox, $this->app['phraseanet.appbox'], 'test', $this->app['authentication']->getUser());
     $this->app['acl']->get($this->app['authentication']->getUser())->give_access_to_base([$collection->get_base_id()]);
     $this->app['acl']->get($this->app['authentication']->getUser())->update_rights_to_base($collection->get_base_id(), ['canpush' => 1, 'cancmd' => 1, 'canputinalbum' => 1, 'candwnldhd' => 1, 'candwnldpreview' => 1, 'canadmin' => 1, 'actif' => 1, 'canreport' => 1, 'canaddrecord' => 1, 'canmodifrecord' => 1, 'candeleterecord' => 1, 'chgstatus' => 1, 'imgtools' => 1, 'manage' => 1, 'modify_struct' => 1, 'nowatermark' => 1]);
     foreach (['PhraseanetIndexer', 'Subdefs', 'WriteMetadata'] as $jobName) {
         $job = $this->app['task-manager.job-factory']->create($jobName);
         $this->app['manipulator.task']->create($job->getName(), $job->getJobId(), $job->getEditor()->getDefaultSettings($this->app['conf']), $job->getEditor()->getDefaultPeriod());
     }
 }
예제 #5
0
 protected function doExecute(InputInterface $input, OutputInterface $output)
 {
     $databox = $this->container->findDataboxById((int) $input->getArgument('databox_id'));
     $new_collection = \collection::create($this->container, $databox, $this->container->getApplicationBox(), $input->getArgument('collname'));
     if ($new_collection && $input->getOption('base_id_rights')) {
         $query = $this->container['phraseanet.user-query'];
         $total = $query->on_base_ids([$input->getOption('base_id_rights')])->get_total();
         $n = 0;
         while ($n < $total) {
             $results = $query->limit($n, 40)->execute()->get_results();
             foreach ($results as $user) {
                 $this->container->getAclForUser($user)->duplicate_right_from_bas($input->getOption('base_id_rights'), $new_collection->get_base_id());
             }
             $n += 40;
         }
     }
     $app = $this->container;
     $this->container['manipulator.acl']->resetAdminRights($this->container['repo.users']->findAdmins());
 }
예제 #6
0
 protected function doExecute(InputInterface $input, OutputInterface $output)
 {
     $databox = $this->container['phraseanet.appbox']->get_databox((int) $input->getArgument('databox_id'));
     $new_collection = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], $input->getArgument('collname'));
     if ($new_collection && $input->getOption('base_id_rights')) {
         $query = new \User_Query($this->container);
         $total = $query->on_base_ids([$input->getOption('base_id_rights')])->get_total();
         $n = 0;
         while ($n < $total) {
             $results = $query->limit($n, 40)->execute()->get_results();
             foreach ($results as $user) {
                 $this->container['acl']->get($user)->duplicate_right_from_bas($input->getOption('base_id_rights'), $new_collection->get_base_id());
             }
             $n += 40;
         }
     }
     $app = $this->container;
     $this->container['manipulator.acl']->resetAdminRights($this->container['manipulator.user']->getRepository()->findAdmins());
     $this->container['dispatcher']->dispatch(PhraseaEvents::COLLECTION_CREATE, new CollectionCreateEvent($new_collection));
 }
 private function generateCollection(\Pimple $DI)
 {
     $coll = $collection_no_acces = $collection_no_acces_by_status = $db = null;
     foreach ($this->container['phraseanet.appbox']->get_databoxes() as $databox) {
         foreach ($databox->get_collections() as $collection) {
             if ($collection_no_acces instanceof \collection && !$collection_no_acces_by_status) {
                 $collection_no_acces_by_status = $collection;
             }
             if ($coll instanceof \collection && !$collection_no_acces) {
                 $collection_no_acces = $collection;
             }
             if (!$coll) {
                 $coll = $collection;
             }
             if ($coll instanceof \collection && $collection_no_acces instanceof \collection && $collection_no_acces_by_status instanceof \collection) {
                 break 2;
             }
         }
     }
     $DI['databox'] = $coll->get_databox();
     $DI['coll'] = $coll;
     if (!$collection_no_acces instanceof collection) {
         $collection_no_acces = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], 'BIBOO', $DI['user']);
     }
     $DI['coll_no_access'] = $collection_no_acces;
     if (!$collection_no_acces_by_status instanceof collection) {
         $collection_no_acces_by_status = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], 'BIBOONOACCESBYSTATUS', $DI['user']);
     }
     $DI['coll_no_status'] = $collection_no_acces_by_status;
 }
예제 #8
0
 /**
  * @covers Alchemy\Phrasea\Controller\Admin\Database::emptyDatabase
  */
 public function testPostEmptyBaseWithHighRecordAmount()
 {
     $this->setAdmin(true);
     $base = $this->createDatabox();
     $collection = \collection::create(self::$DI['app'], $base, self::$DI['app']['phraseanet.appbox'], 'TESTTODELETE');
     self::$createdCollections[] = $collection;
     $sql = 'INSERT INTO record
           (coll_id, record_id, parent_record_id, moddate, credate
             , type, sha256, uuid, originalname, mime)
         VALUES
           (:coll_id, null, :parent_record_id, NOW(), NOW()
           , :type, :sha256, :uuid
           , :originalname, :mime)';
     $stmt = $base->get_connection()->prepare($sql);
     $i = 0;
     while ($i < 502) {
         $stmt->execute([':coll_id' => $collection->get_coll_id(), ':parent_record_id' => 0, ':type' => 'unknown', ':sha256' => null, ':uuid' => \uuid::generate_v4(), ':originalname' => null, ':mime' => null]);
         $i++;
     }
     $stmt->closeCursor();
     if ($collection->get_record_amount() < 500) {
         $this->markTestSkipped('No enough records added');
     }
     $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/empty/');
     $json = $this->getJson(self::$DI['client']->getResponse());
     $this->assertTrue($json->success);
     if (count(self::$DI['app']['EM']->getRepository('Phraseanet:Task')->findAll()) === 0) {
         $this->fail('Task for empty collection has not been created');
     }
     $base->unmount_databox();
     $base->delete();
 }
예제 #9
0
 private function generateCollection(\Pimple $DI)
 {
     $coll = $collection_no_acces = $collection_no_acces_by_status = null;
     /** @var \databox[] $databoxes */
     $databoxes = $this->container->getDataboxes();
     foreach ($databoxes as $databox) {
         foreach ($databox->get_collections() as $collection) {
             if ($collection_no_acces instanceof \collection && !$collection_no_acces_by_status) {
                 $collection_no_acces_by_status = $collection;
             }
             if ($coll instanceof \collection && !$collection_no_acces) {
                 $collection_no_acces = $collection;
             }
             if (!$coll) {
                 $coll = $collection;
             }
             if ($coll instanceof \collection && $collection_no_acces instanceof \collection && $collection_no_acces_by_status instanceof \collection) {
                 break 2;
             }
         }
     }
     $DI['databox'] = $databox = $coll->get_databox();
     $DI['coll'] = $coll;
     if (!$collection_no_acces instanceof \collection) {
         $collection_no_acces = \collection::create($this->container, $databox, $this->container->getApplicationBox(), 'COLL_TEST_NO_ACCESS', $DI['user']);
     }
     $DI['coll_no_access'] = $collection_no_acces;
     if (!$collection_no_acces_by_status instanceof \collection) {
         $collection_no_acces_by_status = \collection::create($this->container, $databox, $this->container->getApplicationBox(), 'COLL_TEST_NO_ACCESS_BY_STATUS', $DI['user']);
     }
     $DI['coll_no_status'] = $collection_no_acces_by_status;
 }
예제 #10
0
 /**
  * Create a new collection
  *
  * @param  Application $app        The silex application
  * @param  Request     $request    The current HTTP request
  * @param  integer     $databox_id The requested databox
  * @return Response
  */
 public function createCollection(Application $app, Request $request, $databox_id)
 {
     if (($name = trim($request->request->get('name', ''))) === '') {
         return $app->redirectPath('admin_database_display_new_collection_form', ['databox_id' => $databox_id, 'error' => 'name']);
     }
     try {
         $databox = $app['phraseanet.appbox']->get_databox($databox_id);
         $collection = \collection::create($app, $databox, $app['phraseanet.appbox'], $name, $app['authentication']->getUser());
         if ($request->request->get('ccusrothercoll') === "on" && null !== ($othcollsel = $request->request->get('othcollsel'))) {
             $query = $app['phraseanet.user-query'];
             $total = $query->on_base_ids([$othcollsel])->get_total();
             $n = 0;
             while ($n < $total) {
                 $results = $query->limit($n, 20)->execute()->get_results();
                 foreach ($results as $user) {
                     $app['acl']->get($user)->duplicate_right_from_bas($othcollsel, $collection->get_base_id());
                 }
                 $n += 20;
             }
         }
         $app['dispatcher']->dispatch(PhraseaEvents::COLLECTION_CREATE, new CollectionCreateEvent($collection));
         return $app->redirectPath('admin_display_collection', ['bas_id' => $collection->get_base_id(), 'success' => 1, 'reload-tree' => 1]);
     } catch (\Exception $e) {
         return $app->redirectPath('admin_database_submit_collection', ['databox_id' => $databox_id, 'error' => 'error']);
     }
 }
예제 #11
0
 /**
  * Create a new collection
  *
  * @param  Request $request    The current HTTP request
  * @param  integer $databox_id The requested databox
  * @return Response
  */
 public function createCollection(Request $request, $databox_id)
 {
     if (($name = trim($request->request->get('name', ''))) === '') {
         return $this->app->redirectPath('admin_database_display_new_collection_form', ['databox_id' => $databox_id, 'error' => 'name']);
     }
     try {
         $databox = $this->findDataboxById($databox_id);
         $collection = \collection::create($this->app, $databox, $this->getApplicationBox(), $name, $this->getAuthenticator()->getUser());
         if ($request->request->get('ccusrothercoll') === "on" && null !== ($othcollsel = $request->request->get('othcollsel'))) {
             $query = $this->createUserQuery();
             $total = $query->on_base_ids([$othcollsel])->get_total();
             $n = 0;
             while ($n < $total) {
                 $results = $query->limit($n, 20)->execute()->get_results();
                 foreach ($results as $user) {
                     $this->getAclForUser($user)->duplicate_right_from_bas($othcollsel, $collection->get_base_id());
                 }
                 $n += 20;
             }
         }
         return $this->app->redirectPath('admin_display_collection', ['bas_id' => $collection->get_base_id(), 'success' => 1, 'reload-tree' => 1]);
     } catch (\Exception $e) {
         return $this->app->redirectPath('admin_database_submit_collection', ['databox_id' => $databox_id, 'error' => 'error']);
     }
 }
예제 #12
0
 public function getCollectionsCombinaison()
 {
     $othercollection = $collection = null;
     $app = $this->loadApp();
     $databoxes = $app['phraseanet.appbox']->get_databoxes();
     if (count($databoxes) === 0) {
         $this->fail('Unable to find collections');
     }
     $databox = array_pop($databoxes);
     foreach ($databoxes as $db) {
         if (!$collection) {
             foreach ($db->get_collections() as $coll) {
                 $collection = $coll;
                 break;
             }
         }
         if (!$othercollection && $collection) {
             foreach ($db->get_collections() as $coll) {
                 if ($coll->get_base_id() != $collection->get_base_id()) {
                     $othercollection = $coll;
                     break;
                 }
             }
         }
     }
     if (null === $othercollection) {
         $othercollection = \collection::create($app, $databox, $app['phraseanet.appbox'], 'other coll');
     }
     if (null === $collection) {
         $collection = \collection::create($app, $databox, $app['phraseanet.appbox'], 'other coll');
     }
     return [[[$collection], $collection, true], [$collection, $collection, true], [$collection, null, true], [$collection, $othercollection, false], [[$collection], $othercollection, false]];
 }