Beispiel #1
0
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     $adapter = $this->container->get('db');
     $tableManagerMysql = new TableManagerMysql($adapter);
     $tableManagerMysql->deleteTable($this->object->getStore()->getTable());
     $tableManagerMysql->deleteTable($this->object->getQueue()->getStore()->getTable());
 }
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     $adapter = $this->container->get('db');
     $tableManagerMysql = new TableManagerMysql($adapter);
     $tableManagerMysql->deleteTable('messages_test');
     $tableManagerMysql->deleteTable('promises_test');
 }
Beispiel #3
0
 /**
  * {@inherit}
  *
  * {@inherit}
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $config = $container->get('config');
     $this->tableName = isset($config[self::KEY][self::KEY_TABLE_NAME]) ? $config[self::KEY][self::KEY_TABLE_NAME] : (isset($options[self::KEY_TABLE_NAME]) ? $options[self::KEY_TABLE_NAME] : self::TABLE_NAME);
     $this->db = $container->has('db') ? $container->get('db') : null;
     if (is_null($this->db)) {
         throw new QueueException('Can\'t create db Adapter');
     }
     if ($container->has(TableManagerMysql::KEY_IN_CONFIG)) {
         $tableManager = $container->get(TableManagerMysql::KEY_IN_CONFIG);
     } else {
         $tableManager = new TableManagerMysql($this->db);
     }
     $hasPromiseStoreTable = $tableManager->hasTable($this->tableName);
     if (!$hasPromiseStoreTable) {
         $tableManager->rewriteTable($this->tableName, $this->promiseTableData);
     }
     $messagesStore = $container->has(Message\Factory\StoreFactory::KEY) ? $container->get(Message\Factory\StoreFactory::KEY) : null;
     if (is_null($messagesStore)) {
         throw new QueueException('Can\'t create Messages Store');
     }
     $promisesStore = $container->has(Promise\Factory\StoreFactory::KEY) ? $container->get(Promise\Factory\StoreFactory::KEY) : null;
     if (is_null($promisesStore)) {
         throw new QueueException('Can\'t create Promises Store');
     }
     return new Store($this->tableName, $this->db, $messagesStore, $promisesStore);
 }
 public function __invoke(ContainerInterface $container, $reqName, $requestedName)
 {
     $config = $container->get('config');
     $serviceConfig = $config[AbstractDataStoreFactory::KEY_DATASTORE][$requestedName];
     if (isset($serviceConfig[DbTableAbstractFactory::KEY_TABLE_GATEWAY])) {
         if ($container->has($serviceConfig[DbTableAbstractFactory::KEY_TABLE_GATEWAY])) {
             $tableGateway = $container->get($serviceConfig[DbTableAbstractFactory::KEY_TABLE_GATEWAY]);
         } else {
             throw new DataStoreException('Can\'t create ' . $serviceConfig[DbTableAbstractFactory::KEY_TABLE_GATEWAY]);
         }
     } else {
         if (isset($serviceConfig[DbTableAbstractFactory::KEY_TABLE_NAME])) {
             $tableName = $serviceConfig[DbTableAbstractFactory::KEY_TABLE_NAME];
             $dbServiceName = isset($serviceConfig[DbTableAbstractFactory::KEY_DB_ADAPTER]) ? $serviceConfig[DbTableAbstractFactory::KEY_DB_ADAPTER] : 'db';
             $db = $container->has($dbServiceName) ? $container->get($dbServiceName) : null;
             if ($container->has('TableManagerMysql')) {
                 $tableManager = $container->get('TableManagerMysql');
             } else {
                 $tableManager = new TableManagerMysql($db);
             }
             $hasTable = $tableManager->hasTable($tableName);
             if (!$hasTable) {
                 $tableManager->rewriteTable($tableName, $this->tablePreferenceTableData);
             }
             $tableGateway = new TableGateway($tableName, $db);
         } else {
             throw new DataStoreException('There is not table name for ' . $requestedName . 'in config \'dataStore\'');
         }
     }
     $class = (isset($serviceConfig[AbstractFactoryAbstract::KEY_CLASS]) and is_a($serviceConfig[AbstractFactoryAbstract::KEY_CLASS], DbTable::class, true)) ? $serviceConfig[AbstractFactoryAbstract::KEY_CLASS] : DbTable::class;
     return new $class($tableGateway);
 }
 public function __invoke(ContainerInterface $container, $name, $requestedName)
 {
     $config = $container->get('config');
     $serviceConfig = $config[self::KEY_DATASTORE][self::KEY_ALL_NOTIFICATION];
     if (isset($serviceConfig[self::KEY_TABLE_GATEWAY])) {
         if ($container->has($serviceConfig[self::KEY_TABLE_GATEWAY])) {
             $tableGateway = $container->get($serviceConfig[self::KEY_TABLE_GATEWAY]);
         } else {
             throw new DataStoreException('Can\'t create ' . $serviceConfig[self::KEY_TABLE_GATEWAY]);
         }
     } else {
         if (isset($serviceConfig[self::KEY_TABLE_NAME])) {
             $tableName = $serviceConfig[self::KEY_TABLE_NAME];
             $dbServiceName = isset($serviceConfig[self::KEY_DB_ADAPTER]) ? $serviceConfig[self::KEY_DB_ADAPTER] : 'db';
             $db = $container->has($dbServiceName) ? $container->get($dbServiceName) : null;
             /*if ($container->has('TableManagerMysql')) {
                   $tableManager = $container->get('TableManagerMysql');
               } else {*/
             $tableManager = new TableManagerMysql($db);
             /*}*/
             $hasTable = $tableManager->hasTable($tableName);
             if (!$hasTable) {
                 $tableManager->rewriteTable($tableName, $this->tablePreferenceTableData);
             }
             $tableGateway = new TableGateway($tableName, $db);
         } else {
             throw new DataStoreException('There is not table name for ' . self::KEY_ALL_NOTIFICATION . 'in config \'dataStore\'');
         }
     }
     return new DbTable($tableGateway);
 }
Beispiel #6
0
 public function install()
 {
     $tableManager = new TableManager($this->emailDbAdapter);
     $tableConfig = $this->getTableConfig();
     $tableName = Email::TABLE_NAME;
     $tableManager->createTable($tableName, $tableConfig);
 }
Beispiel #7
0
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     $adapter = $this->container->get('db');
     $tableManagerMysql = new TableManagerMysql($adapter);
     $tableManagerMysql->deleteTable($this->store->getTable());
     $tableManagerMysql->deleteTable($this->store->getMessagesStore()->getTable());
     $tableManagerMysql->deleteTable($this->store->getPromisesStore()->getTable());
 }
Beispiel #8
0
 public function getLinkedColumn($entityName, $propColumn)
 {
     /** @var Adapter $adapter */
     $adapter = $this->dbTable->getAdapter();
     $mysqlManager = new TableManagerMysql($adapter);
     $columnsNames = $mysqlManager->getColumnsNames($this->dbTable->table);
     //'prop_name.column_name' or 'prop_name'
     $linkedColumn = strpos($propColumn, '.') ? isset(explode('.', $propColumn)[1]) && in_array(explode('.', $propColumn)[1], $columnsNames) ? explode('.', $propColumn)[1] : null : (in_array($entityName . SysEntities::ID_SUFFIX, $columnsNames) ? $entityName . SysEntities::ID_SUFFIX : (in_array(SysEntities::TABLE_NAME . SysEntities::ID_SUFFIX, $columnsNames) ? SysEntities::TABLE_NAME . SysEntities::ID_SUFFIX : null));
     return $linkedColumn;
 }
Beispiel #9
0
 public function install()
 {
     if (getenv('APP_ENV') === 'dev') {
         //develop only
         $tablesConfigDevelop = [TableManager::KEY_TABLES_CONFIGS => Store::$develop_tables_config];
         $tableManager = new TableManager($this->dbAdapter, $tablesConfigDevelop);
         $tableManager->rewriteTable(Store::PRODUCT_TABLE_NAME);
         $tableManager->rewriteTable(Store::IMAGE_TABLE_NAME);
         $tableManager->rewriteTable(Store::CATEGORY_TABLE_NAME);
         $tableManager->rewriteTable(Store::CATEGORY_PRODUCT_TABLE_NAME);
     }
 }
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $config = $container->get('config');
     $tableName = isset($config[self::KEY][self::KEY_TABLE_NAME]) ? $config[self::KEY][self::KEY_TABLE_NAME] : (isset($options[self::KEY_TABLE_NAME]) ? $options[self::KEY_TABLE_NAME] : self::TABLE_NAME);
     $db = $container->has('db') ? $container->get('db') : null;
     if (is_null($db)) {
         throw new UnexpectedValueException('Can\'t create db Adapter');
     }
     if ($container->has(TableManagerMysql::KEY_IN_CONFIG)) {
         $tableManager = $container->get(TableManagerMysql::KEY_IN_CONFIG);
     } else {
         $tableManager = new TableManagerMysql($db);
     }
     $hasPromiseStoreTable = $tableManager->hasTable($tableName);
     if (!$hasPromiseStoreTable) {
         $tableManager->rewriteTable($tableName, $this->taskStoreData);
     }
     return new Store($tableName, $db);
 }
 /**
  * {@inherit}
  *
  * {@inherit}
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $this->db = $container->has('db') ? $container->get('db') : null;
     if (is_null($this->db)) {
         throw new DataStoreException('Can\'t create Zend\\Db\\TableGateway\\TableGateway for ' . self::TABLE_NAME);
     }
     $tableManager = new TableManagerMysql($this->db, $this->tableConfig);
     //        $hasTable = $tableManager->hasTable(self::TABLE_NAME);
     //        if (!$hasTable) {
     if (!$tableManager->hasTable(self::TABLE_NAME)) {
         $tableManager->createTable(self::TABLE_NAME, self::TABLE_NAME);
     }
     $tableGateway = new TableGateway(self::TABLE_NAME, $this->db);
     $this->dataStore = new DbTable($tableGateway);
     //        // Fill table using DbTable DataStore interface
     //        if (!$hasTable) {
     //            $this->fillTable($container);
     //        }
     return $this->dataStore;
 }
Beispiel #12
0
 public function install()
 {
     if (getenv('APP_ENV') === 'dev') {
         //develop only
         $tablesConfigDevelop = [TableManager::KEY_TABLES_CONFIGS => array_merge(SysEntities::getTableConfigProdaction(), StoreCatalog::$develop_tables_config)];
         $tableManager = new TableManager($this->dbAdapter, $tablesConfigDevelop);
         $tableManager->rewriteTable(SysEntities::TABLE_NAME);
         $tableManager->rewriteTable(StoreCatalog::PRODUCT_TABLE_NAME);
         $tableManager->rewriteTable(StoreCatalog::TAG_TABLE_NAME);
         $tableManager->rewriteTable(StoreCatalog::MAINICON_TABLE_NAME);
         $tableManager->rewriteTable(StoreCatalog::MAIN_SPECIFIC_TABLE_NAME);
         $tableManager->rewriteTable(StoreCatalog::CATEGORY_TABLE_NAME);
         $tableManager->rewriteTable(StoreCatalog::PROP_LINKED_URL_TABLE_NAME);
         $tableManager->rewriteTable(StoreCatalog::PROP_PRODUCT_CATEGORY_TABLE_NAME);
         $tableManager->rewriteTable(StoreCatalog::PROP_TAG_TABLE_NAME);
     } else {
         $tablesConfigProdaction = [TableManager::KEY_TABLES_CONFIGS => SysEntities::getTableConfigProdaction()];
         $tableManager = new TableManager($this->dbAdapter, $tablesConfigProdaction);
         $tableManager->createTable(SysEntities::TABLE_NAME);
     }
 }
 public function testStoreFactory__invoke__TableNameFromConfig()
 {
     global $testCase;
     $testCase = 'table_for_test';
     $this->container = (include './config/container.php');
     $this->object = new StoreFactory();
     $this->tableManagerMysql = $this->container->get(TableManagerMysql::KEY_IN_CONFIG);
     // if tables is absent
     $this->tableName = StoreFactory::TABLE_NAME . '_test';
     $this->tableManagerMysql->deleteTable($this->tableName);
     $this->assertFalse($this->tableManagerMysql->hasTable($this->tableName));
     /* @var $store Store */
     $store = $this->container->get(StoreFactory::KEY);
     $this->assertInstanceOf(Store::class, $store);
     // if tables is present
     $this->assertTrue($this->tableManagerMysql->hasTable($this->tableName));
     $store = $this->container->get(StoreFactory::KEY);
     $this->assertInstanceOf(Store::class, $store);
     $this->tableManagerMysql->deleteTable($this->tableName);
     $testCase = 'default';
 }
Beispiel #14
0
 protected function joinedEntitiesItemHandler($itemData, callable $handler)
 {
     /** @var Adapter $adapter */
     $adapter = $this->dbTable->getAdapter();
     $itemInserted = [];
     /** @var Entity $entity */
     foreach ($this->joinedEntities as $entity) {
         if (is_object($entity)) {
             $entityItem = [];
             $mysqlManager = new TableManagerMysql($adapter);
             $columnsNames = $mysqlManager->getColumnsNames($entity->getEntityTableName());
             foreach ($columnsNames as $columnName) {
                 if (isset($itemData[$columnName])) {
                     $entityItem[$columnName] = $itemData[$columnName];
                 }
             }
             $entityItem = $handler($entity, $entityItem);
             $itemInserted = array_merge($itemInserted, $entityItem);
         }
     }
     return $itemInserted;
 }
Beispiel #15
0
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     $adapter = $this->container->get('db');
     $tableManagerMysql = new TableManagerMysql($adapter);
     $tableManagerMysql->deleteTable($this->tableName);
 }
Beispiel #16
0
 /**
  * initialize bound table
  */
 protected function initBound()
 {
     if (!isset($this->boundTables) || empty($this->boundTables)) {
         /** @var Adapter $adapter */
         $adapter = $this->dbTable->getAdapter();
         $tableManager = new TableManagerMysql($adapter);
         $metadata = Factory::createSourceFromAdapter($adapter);
         $this->boundTables = ['single' => [], 'multiple' => []];
         /** @var $constraint \Zend\Db\Metadata\Object\ConstraintObject */
         foreach ($metadata->getConstraints($this->dbTable->table) as $constraint) {
             if ($constraint->isForeignKey()) {
                 $this->boundTables['single'][$constraint->getReferencedTableName()] = ['table' => new Composite(new TableGateway($constraint->getReferencedTableName(), $adapter)), 'myColumn' => $constraint->getColumns()[0], 'column' => $constraint->getReferencedColumns()[0]];
             }
         }
         foreach ($tableManager->getLinkedTables($this->dbTable->table) as $linkedTable) {
             $this->boundTables['multiple'][$linkedTable['TABLE_NAME']] = ['table' => new Composite(new TableGateway($linkedTable['TABLE_NAME'], $adapter)), 'column' => $linkedTable['COLUMN_NAME']];
         }
     }
 }