Пример #1
0
 public function initAcl()
 {
     $conn = $this->getBBApp()->getEntityManager()->getConnection();
     $schema = new \Symfony\Component\Security\Acl\Dbal\Schema(array('class_table_name' => 'acl_classes', 'entry_table_name' => 'acl_entries', 'oid_table_name' => 'acl_object_identities', 'oid_ancestors_table_name' => 'acl_object_identity_ancestors', 'sid_table_name' => 'acl_security_identities'));
     $platform = $conn->getDatabasePlatform();
     foreach ($schema->toSql($platform) as $query) {
         $conn->executeQuery($query);
     }
 }
Пример #2
0
     $database = new \BackBee\Installer\Database($application);
     $database->updateBackBeeSchema();
     $database->updateBundlesSchema();
 } catch (\Exception $e) {
     echo 'Failed to create or to update database with the current exception message : ' . $e->getMessage();
     // to be catched by Debug component
 }
 $entityManager = $application->getEntityManager();
 $connection = $entityManager->getConnection();
 try {
     // Create security Acl tables
     $tablesMapping = ['class_table_name' => 'acl_classes', 'entry_table_name' => 'acl_entries', 'oid_table_name' => 'acl_object_identities', 'oid_ancestors_table_name' => 'acl_object_identity_ancestors', 'sid_table_name' => 'acl_security_identities'];
     foreach ($tablesMapping as $tableName) {
         $connection->executeQuery(sprintf('DROP TABLE IF EXISTS %s', $tableName));
     }
     $schema = new \Symfony\Component\Security\Acl\Dbal\Schema($tablesMapping);
     $platform = $connection->getDatabasePlatform();
     foreach ($schema->toSql($platform) as $query) {
         $connection->executeQuery($query);
     }
     /**
      * Creation of Admin user
      */
     $encoderFactory = $application->getContainer()->get('security.context')->getEncoderFactory();
     $adminUser = new \BackBee\Security\User($_POST['username'], $_POST['user_password'], 'SuperAdmin', 'SuperAdmin');
     $adminUser->setApiKeyEnabled(true)->setActivated(true);
     $encoder = $encoderFactory->getEncoder($adminUser);
     $adminUser->setPassword($encoder->encodePassword($_POST['user_password'], ''))->setEmail($_POST['user_email'])->generateRandomApiKey();
     $entityManager->persist($adminUser);
     $entityManager->flush($adminUser);
     $security = \Symfony\Component\Yaml\Yaml::parse(dirname(__DIR__) . '/repository/Config/security.yml.dist');
 /**
  * Create ACL tables if doesn't exit
  */
 private function checkAclTables()
 {
     $dropTableSql = [];
     $schemaManager = $this->em->getConnection()->getSchemaManager();
     // Create security Acl tables
     $tablesMapping = ['class_table_name' => 'acl_classes', 'entry_table_name' => 'acl_entries', 'oid_table_name' => 'acl_object_identities', 'oid_ancestors_table_name' => 'acl_object_identity_ancestors', 'sid_table_name' => 'acl_security_identities'];
     foreach ($tablesMapping as $key => $value) {
         if ($schemaManager->tablesExist(array($value)) === true) {
             $dropTableSql[] = 'DROP TABLE IF EXISTS `' . $value . '`;';
         }
     }
     if (count($dropTableSql) != count($tablesMapping)) {
         if (!empty($dropTableSql)) {
             $this->em->getConnection()->executeUpdate('SET FOREIGN_KEY_CHECKS=0');
             $this->em->getConnection()->executeQuery(implode(' ', $dropTableSql));
             $this->em->getConnection()->executeUpdate('SET FOREIGN_KEY_CHECKS=1');
         }
         $schema = new \Symfony\Component\Security\Acl\Dbal\Schema($tablesMapping);
         $platform = $this->em->getConnection()->getDatabasePlatform();
         foreach ($schema->toSql($platform) as $query) {
             $this->em->getConnection()->executeQuery($query);
         }
         $this->writeln(sprintf('ACL tables recreated.', $value));
     } else {
         $this->writeln(sprintf('All ACL tables exists.', $value));
     }
 }