Ejemplo n.º 1
0
 public function tearDown()
 {
     $connection = DatabaseManager::getInstance()->getConnection();
     $connection->executeFile(new File(self::SQL_TEARDOWN));
     //        $definer = new ModelDefiner();
     //        $definer->deleteModels($models);
     parent::tearDown();
 }
Ejemplo n.º 2
0
 /**
  * Creates or alters the tables in the database of the provided models
  * @param array $models Array with Model objects
  * @return null
  */
 public function defineModels(array $models)
 {
     $connection = DatabaseManager::getInstance()->getConnection();
     $definer = $connection->getDefiner();
     $isTransactionStarted = $connection->startTransaction();
     try {
         $tables = array();
         foreach ($models as $model) {
             $table = $this->getDatabaseTable($model);
             $definer->defineTable($table);
             $tables[] = $table;
         }
         foreach ($tables as $table) {
             $definer->defineForeignKeys($table);
         }
         $connection->commitTransaction($isTransactionStarted);
     } catch (Exception $exception) {
         $connection->rollbackTransaction($isTransactionStarted);
         throw $exception;
     }
 }
Ejemplo n.º 3
0
 /**
  * Constructs a new database connection model
  * @return null
  */
 public function __construct()
 {
     $this->manager = DatabaseManager::getInstance();
 }
Ejemplo n.º 4
0
 /**
  * Deletes the models for the uninstalled modules
  * @param zibo\admin\model\Installer $installer Instance of the installer
  * @param zibo\library\filesystem\File $modulePath Path of the modules
  * @param array $modules The modules which are uninstalled
  * @return null
  */
 public function deleteModelsForUninstalledModules(Installer $installer, File $modulePath, array $modules)
 {
     $connections = DatabaseManager::getInstance()->getConnections();
     if (!$connections) {
         return;
     }
     ModelManager::getInstance()->defineModels();
 }
 /**
  * @expectedException zibo\library\database\exception\DatabaseException
  */
 public function testSetDefaultConnectionThrowsExceptionWhenNameDoesNotExist()
 {
     $manager = DatabaseManager::getInstance();
     $manager->setDefaultConnectionName('unexistant');
 }
Ejemplo n.º 6
0
 /**
  * Gets all the field types as defined in the database definer
  * @return array Array with the property type as key and as value
  */
 private function getPropertyTypes()
 {
     $connection = DatabaseManager::getInstance()->getConnection();
     $definer = $connection->getDefiner();
     $fieldTypes = $definer->getFieldTypes();
     $propertyTypes = array();
     foreach ($fieldTypes as $fieldType => $databaseType) {
         $propertyTypes[$fieldType] = $fieldType;
     }
     return $propertyTypes;
 }
Ejemplo n.º 7
0
 protected function tearDown()
 {
     Reflection::setProperty(ModelManager::getInstance(), 'instance', null);
     Reflection::setProperty(DatabaseManager::getInstance(), 'instance', null);
     Reflection::setProperty(Zibo::getInstance(), 'instance', null);
 }
Ejemplo n.º 8
0
 /**
  * Gets the driver of the database connection
  * @return zibo\library\database\driver\Driver
  */
 public function getConnection()
 {
     return DatabaseManager::getInstance()->getConnection();
 }