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()); } }
public function createDatabox() { $this->createDatabase(); $connexion = self::$DI['app']['phraseanet.configuration']['main']['database']; try { $conn = self::$DI['app']['dbal.provider']->get(['host' => $connexion['host'], 'port' => $connexion['port'], 'user' => $connexion['user'], 'password' => $connexion['password'], 'dbname' => 'unit_test_db']); $conn->connect(); } catch (DBALException $e) { $this->markTestSkipped('Could not reach DB'); } $databox = \databox::create(self::$DI['app'], $conn, new \SplFileInfo(self::$DI['app']['root.path'] . '/lib/conf.d/data_templates/fr-simple.xml')); self::$createdDataboxes[] = $databox; $rights = ['bas_manage' => '1', 'bas_modify_struct' => '1', 'bas_modif_th' => '1', 'bas_chupub' => '1']; self::$DI['app']['acl']->get(self::$DI['app']['authentication']->getUser())->update_rights_to_sbas($databox->get_sbas_id(), $rights); $databox->registerAdmin(self::$DI['app']['authentication']->getUser()); return $databox; }
/** * Create a new databox * * @param Application $app The silex application * @param Request $request The current HTTP request * * @return RedirectResponse */ public function createDatabase(Application $app, Request $request) { if ('' === ($dbName = $request->request->get('new_dbname', ''))) { return $app->redirectPath('admin_databases', ['error' => 'no-empty']); } if (\p4string::hasAccent($dbName)) { return $app->redirectPath('admin_databases', ['error' => 'special-chars']); } if (null === $request->request->get('new_settings') && null !== ($dataTemplate = $request->request->get('new_data_template'))) { $connexion = $app['conf']->get(['main', 'database']); $hostname = $connexion['host']; $port = $connexion['port']; $user = $connexion['user']; $password = $connexion['password']; $dataTemplate = new \SplFileInfo($app['root.path'] . '/lib/conf.d/data_templates/' . $dataTemplate . '.xml'); try { $connbas = $app['dbal.provider']->get(['host' => $hostname, 'port' => $port, 'user' => $user, 'password' => $password, 'dbname' => $dbName]); $connbas->connect(); } catch (DBALException $e) { return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'database-failed']); } try { $base = \databox::create($app, $connbas, $dataTemplate); $base->registerAdmin($app['authentication']->getUser()); $app['acl']->get($app['authentication']->getUser())->delete_data_from_cache(); return $app->redirectPath('admin_database', ['databox_id' => $base->get_sbas_id(), 'success' => 1, 'reload-tree' => 1]); } catch (\Exception $e) { return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'base-failed']); } } if (null !== $request->request->get('new_settings') && null !== ($hostname = $request->request->get('new_hostname')) && null !== ($port = $request->request->get('new_port')) && null !== ($userDb = $request->request->get('new_user')) && null !== ($passwordDb = $request->request->get('new_password')) && null !== ($dataTemplate = $request->request->get('new_data_template'))) { try { $data_template = new \SplFileInfo($app['root.path'] . '/lib/conf.d/data_templates/' . $dataTemplate . '.xml'); $connbas = $app['dbal.provider']->get(['host' => $hostname, 'port' => $port, 'user' => $userDb, 'password' => $passwordDb, 'dbname' => $dbName]); $connbas->connect(); try { $base = \databox::create($app, $connbas, $data_template); $base->registerAdmin($app['authentication']->getUser()); return $app->redirectPath('admin_database', ['databox_id' => $base->get_sbas_id(), 'success' => 1, 'reload-tree' => 1]); } catch (\Exception $e) { return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'base-failed']); } } catch (\Exception $e) { return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'database-failed']); } } }