/** * Initializes the setup manager. * * @param \Aimeos\MW\DB\Manager\Iface $dbm Database manager * @param array $dbconfig Associative list of database configurations, each with the db resource * name as key and an associative list of "adapter", "host", "database", "username" and "password" keys * @param array|string $taskpath Filesystem paths to the directory which contains the task classes * @param mixed $additional Additionally provided information for the setup tasks if required */ public function __construct(\Aimeos\MW\DB\Manager\Iface $dbm, array $dbconfig, $taskpath, $additional = null) { parent::__construct((array) $taskpath); if (empty($dbconfig)) { throw new \Aimeos\MW\Setup\Exception('No databases configured in resource config file'); } $this->dbm = $dbm; $this->additional = $additional; $schemas = array(); $this->type = isset($dbconfig['db']['adapter']) ? $dbconfig['db']['adapter'] : ''; foreach ($dbconfig as $rname => $dbconf) { if (!isset($dbconf['adapter'])) { throw new \Aimeos\MW\Setup\Exception(sprintf('Configuration parameter "%1$s" missing in "%2$s"', 'adapter', $rname)); } if (!isset($dbconf['database'])) { throw new \Aimeos\MW\Setup\Exception(sprintf('Configuration parameter "%1$s" missing in "%2$s"', 'database', $rname)); } $this->conns[$rname] = $dbm->acquire($rname); $schemas[$rname] = $this->createSchema($this->conns[$rname], $dbconf['adapter'], $dbconf['database']); } $this->setupTasks((array) $taskpath, $this->conns, $schemas); }
/** * Returns value of a catalog_index column. * * @param \Aimeos\MW\DB\Manager\Iface $dbm Database Manager for connection * @param string $sql Specified db query to find only one value * @param string $column Column where to search * @param integer $siteId Siteid of the db entry * @param integer $productId Product id * @return string $value Value returned for specified sql statement * @throws \Exception If column not available or error during a connection to db */ protected function getValue(\Aimeos\MW\DB\Manager\Iface $dbm, $sql, $column, $siteId, $productId) { $config = $this->context->getConfig(); if ($config->get('resource/db-product') === null) { $dbname = $config->get('resource/default', 'db'); } else { $dbname = 'db-product'; } $conn = $dbm->acquire($dbname); try { $stmt = $conn->create($sql); $stmt->bind(1, $siteId, \Aimeos\MW\DB\Statement\Base::PARAM_INT); $stmt->bind(2, $productId, \Aimeos\MW\DB\Statement\Base::PARAM_INT); $result = $stmt->execute(); if (($row = $result->fetch()) === false) { throw new \Exception('No rows available'); } if (!isset($row[$column])) { throw new \Exception(sprintf('Column "%1$s" not available for "%2$s"', $column, $sql)); } $value = $row[$column]; $dbm->release($conn, $dbname); } catch (\Exception $e) { $dbm->release($conn, $dbname); throw $e; } return $value; }