Ejemplo n.º 1
1
 private function singleImport($config, OutputInterface &$output, $entity_key = null)
 {
     $this->connection = $this->connectionFactory->createConnection($config['database']);
     $this->connection->getConfiguration()->getSQLLogger(null);
     if ($entity_key) {
         if (!isset($config['maps'][$entity_key])) {
             throw new \Exception("Entity alias not found: " . $entity_key);
         }
         $map = $config['maps'][$entity_key];
         if (!$this->container->has($map['old_data']['service_id'])) {
             throw new \Exception("Service not exists: " . $map['old_data']['service_id']);
         }
         $result = $this->importEntity($map);
         $output->writeln("<info>Total " . count($result) . " {$entity_key} imported </info>");
     } else {
         foreach ((array) $config['maps'] as $key => $map) {
             if (!$this->container->has($map['old_data']['service_id'])) {
                 throw new \Exception("Service not exists: " . $map['old_data']['service_id']);
             }
             $offset = 0;
             do {
                 $result = $this->importEntity($map);
                 $output->writeln("<info>Total " . count($result) . " {$key} imported </info>");
                 if (!$result) {
                     break;
                 }
                 $offset++;
                 $this->setOffset($offset);
             } while (true);
         }
     }
     $this->connection->close();
 }
Ejemplo n.º 2
0
 /**
  * MysqlRequirement constructor.
  *
  * @param string $host
  * @param string $name
  * @param string $user
  * @param string $password
  */
 public function __construct($host, $name, $user, $password, ConnectionFactory $factory)
 {
     try {
         $factory->createConnection(array('pdo' => new \PDO("mysql:host={$host};dbname={$name}", $user, $password)));
         $this->addRequirement(true, "Mysql connection", "");
     } catch (\PDOException $e) {
         $this->addRequirement(false, "Mysql connection requirement failed", $e->getMessage());
     }
 }
Ejemplo n.º 3
0
 /**
  * Create a connection by name.
  *
  * @param array         $params
  * @param Configuration $config
  * @param EventManager  $eventManager
  * @param array         $mappingTypes
  *
  * @return \Doctrine\DBAL\Connection
  */
 public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
 {
     $dbName = $this->getDbNameFromEnv($params['dbname']);
     if ($params['driver'] === 'pdo_sqlite') {
         $params['path'] = str_replace("__DBNAME__", $dbName, $params['path']);
     } else {
         $params['dbname'] = $dbName;
     }
     return parent::createConnection($params, $config, $eventManager, $mappingTypes);
 }
 public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
 {
     // Discover and override $params array here.
     // A real-world example might obtain them from zookeeper,
     // consul or etcd for example. You'll probably want to cache
     // anything you obtain from such a service too.
     //print_r($_SERVER);REMOTE_ADDR
     $params['driver'] = 'pdo_mysql';
     $params['host'] = 'localhost';
     $params['port'] = 3306;
     /*
      if ($_SERVER["REMOTE_ADDR"] == '127.0.0.1') {
     
      $params['dbname'] = 'partsbox_symfony';
      $params['user'] = '******';
      $params['password'] = '******';
     
      } else {
      $params['dbname'] = 'partsbox_db2';
      $params['user'] = '******';
      $params['password'] = '******';
      }
     */
     $databale = @explode(".", $_SERVER["HTTP_HOST"]);
     if ($_SERVER["DOCUMENT_ROOT"] == 'C:\\symfony\\alexander\\web') {
         $params['dbname'] = 'partsbox_symfony6';
         $params['user'] = '******';
         $params['password'] = '******';
     } elseif ($databale[0]) {
         $params['dbname'] = 'partsbox_' . $databale[0];
         $params['user'] = '******';
         $params['password'] = '******';
     } else {
         $params['dbname'] = 'partsbox_symfony6';
         $params['user'] = '******';
         $params['password'] = '******';
         $params['dbname'] = 'partsbox_partsbox6';
         $params['user'] = '******';
         $params['password'] = '******';
     }
     return parent::createConnection($params, $config, $eventManager, $mappingTypes);
     /*
             if ($_SERVER["REQUEST_URI"] == '/account/test/asddasdgh') {
        return parent::createConnection($params, $config, $eventManager, $mappingTypes);
             } else {
        echo file_get_contents("http://localhost:8000/account/test/asddasdgh");
        return parent::createConnection($params, $config, $eventManager, $mappingTypes);
             }
     * 
     */
 }
 public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
 {
     // Discover and override $params array here.
     // A real-world example might obtain them from zookeeper,
     // consul or etcd for example. You'll probably want to cache
     // anything you obtain from such a service too.
     $params['driver'] = 'pdo_mysql';
     $params['host'] = 'localhost';
     $params['port'] = 3306;
     $params['dbname'] = 'symfony_booking';
     $params['user'] = '******';
     $params['password'] = '******';
     //continue with regular connection creation using new params
     return parent::createConnection($params, $config, $eventManager, $mappingTypes);
 }
Ejemplo n.º 6
0
 /**
  * @param array $params
  * @param Configuration|null $config
  * @param EventManager|null $eventManager
  * @param array $mappingTypes
  *
  * @return Connection
  */
 public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
 {
     try {
         // there is no other way since we don't have access to the container, but it works yeey, but I'm still sorry
         $session = new Session();
         if (!$session->has('installation_data') || $session->get('installation_data')->getDbHostname() === null) {
             return $this->getInstallerConnection($params, $config, $eventManager);
         }
         /** @var InstallationData $installationData */
         $installationData = $session->get('installation_data');
         $params['host'] = $installationData->getDbHostname();
         $params['port'] = $installationData->getDbPort();
         $params['dbname'] = $installationData->getDbDatabase();
         $params['user'] = $installationData->getDbUsername();
         $params['password'] = $installationData->getDbPassword();
         //continue with regular connection creation using new params
         return parent::createConnection($params, $config, $eventManager, $mappingTypes);
     } catch (ConnectionException $e) {
         return $this->getInstallerConnection($params, $config, $eventManager);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
 {
     // @todo
     //   - handle connection name
     // Matches for default parameters
     if (empty($params['password']) && empty($params['port']) && 'localhost' === $params['host']) {
         // Attempt to create connection using the Drupal \PDO instance
         if (class_exists('\\Database')) {
             $connection = \Database::getConnection();
             switch ($connection->driver()) {
                 case 'mysql':
                     $driver = 'pdo_mysql';
                     break;
                 case 'pgsql':
                     $driver = 'pdo_pgsql';
                     break;
                 case 'sqlite':
                     $driver = 'pdo_sqlite';
                     break;
                 default:
                     throw new \InvalidArgumentException(sprintf("%s: cannot map driver to doctrine's", $connection->driver()));
             }
             $drupalInfo = $connection->getConnectionOptions();
             if (!empty($drupalInfo['prefix']['default'])) {
                 throw new \InvalidArgumentException("Drupal to Doctrine DBAL convertion does not supports table name prefix");
             }
             $map = ['database' => 'dbname', 'port' => 'port', 'password' => 'password', 'username' => 'user', 'host' => 'host'];
             $params = ['driver' => $driver];
             foreach ($map as $key => $target) {
                 if (!empty($drupalInfo[$key])) {
                     $params[$target] = $drupalInfo[$key];
                 }
             }
             return parent::createConnection($params, $config, $eventManager, $mappingTypes);
             // return parent::createConnection(['driver' => $driver, 'pdo' => $connection], $config, $eventManager, $mappingTypes);
         }
     }
     return parent::createConnection($params, $config, $eventManager, $mappingTypes);
 }
Ejemplo n.º 8
0
 /**
  * Create a connection by name.
  *
  * @param array         $params
  * @param Configuration $config
  * @param EventManager  $eventManager
  * @param array         $mappingTypes
  *
  * @return \Doctrine\DBAL\Connection
  */
 public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
 {
     if (isset($params['dbname'])) {
         $dbName = $this->getDbNameFromEnv($params['dbname']);
     } else {
         $dbName = $this->getDbNameFromEnv($params['master']['dbname']);
     }
     if ($params['driver'] === 'pdo_sqlite') {
         if (isset($params['path'])) {
             $params['path'] = str_replace("__DBNAME__", $dbName, $params['path']);
         }
         if (isset($params['master']['path'])) {
             $params['master']['path'] = str_replace("__DBNAME__", $dbName, $params['master']['path']);
         }
         if (!empty($params['slaves'])) {
             foreach ($params['slaves'] as &$slave) {
                 $slave['path'] = str_replace("__DBNAME__", $dbName, $slave['path']);
             }
         }
     } else {
         $params['dbname'] = $dbName;
     }
     return parent::createConnection($params, $config, $eventManager, $mappingTypes);
 }
Ejemplo n.º 9
0
 /**
  * Create a connection by name.
  *
  * @param array         $params
  * @param Configuration $config
  * @param EventManager  $eventManager
  * @param array         $mappingTypes
  *
  * @return \Doctrine\DBAL\Connection
  */
 public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
 {
     $params['dbname'] = $this->getDbNameFromEnv($params['dbname']);
     return parent::createConnection($params, $config, $eventManager, $mappingTypes);
 }