public function setUp() { $this->dispatcher = $this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"); $session = new Session(new MockArraySessionStorage()); $this->request = new Request(); $this->request->setSession($session); $dbinfo = new DatabaseInfo(); $dbinfo->setHostname('localhost'); $dbinfo->setDbname('thelia1543'); $dbinfo->setUsername('thelia1543'); $dbinfo->setPassword('honolulu'); $this->thelia1_db = new Db($this->request); $this->thelia1_db->setDbInfo($dbinfo); }
public function checkDbAction() { if (null !== ($response = $this->checkAuth(self::RESOURCE_CODE, array(), AccessManager::VIEW))) { return $response; } $error_message = false; $dbinfo = new DatabaseInfo(); $dbinfo->setHostname(trim($this->getRequest()->get('hostname')))->setUsername(trim($this->getRequest()->get('username')))->setPassword($this->getRequest()->get('password'))->setDbname(trim($this->getRequest()->get('dbname')))->setClientDirectory(trim($this->getRequest()->get('client_directory'))); if (!$dbinfo->isValid()) { $error_message = Translator::getInstance()->trans("Please enter all required information.", [], ImportT1::DOMAIN); } else { $this->getDb()->setDbInfo($dbinfo); // Try to connect to database try { $db = $this->container->get('importt1.db'); $db->connect(); // Check if we can find a Thelia database in this db try { $db->query("select * from variable"); $hdl = $db->query("select valeur from variable where nom = 'version'"); $version = $db->fetch_column($hdl); if (intval(substr($version, 0, 3)) < self::MIN_VERSION) { $error_message = $this->getTranslator()->trans("A Thelia %version database was found. Unfortunately, only Thelia 1.4.2 or newer databases may be imported. Please upgrade this Thelia 1 installation up to the latest available Thelia 1 version.", array("%version" => rtrim(preg_replace("/(.)/", "\$1.", $version), ".")), ImportT1::DOMAIN); } else { $dir = $dbinfo->getClientDirectory(); if (!empty($dir)) { try { // Check the "client" path if (!is_dir($dbinfo->getClientDirectory())) { $error_message = $this->getTranslator()->trans("The directory %dir was not found. Please check your input and try again.", array("%dir" => $dbinfo->getClientDirectory()), ImportT1::DOMAIN); } else { $photos_dir = sprintf("%s%sgfx%sphotos", $dir, DS, DS); if (!is_dir($photos_dir)) { $error_message = $this->getTranslator()->trans("No Thelia 1 image directory can be found in %dir directory.", array("%dir" => $dbinfo->getClientDirectory()), ImportT1::DOMAIN); } } } catch (\Exception $ex) { $error_message = $this->getTranslator()->trans("Failed to access to %dir directory. (%ex)", ["%dir" => $dbinfo->getClientDirectory(), '%ex' => $ex->getMessage()], ImportT1::DOMAIN); } } } } catch (\Exception $ex) { $error_message = $this->getTranslator()->trans("No Thelia 1 database was found in this database. Please check your input and try again. (%ex)", ['%ex' => $ex->getMessage()], ImportT1::DOMAIN); } } catch (\Exception $ex) { $error_message = $this->getTranslator()->trans("Failed to connect to database using the parameters below. Please check your input and try again. (%ex)", ['%ex' => $ex->getMessage()], ImportT1::DOMAIN); } } if ($error_message !== false) { // Check that we have at least one payment and one delivery module if (null === ModuleQuery::create()->findOneByType(BaseModule::DELIVERY_MODULE_TYPE)) { $error_message = $this->getTranslator()->trans("No active delivery module was found. Please install and activate at least one delivery module.", [], ImportT1::DOMAIN); } } if ($error_message !== false) { // Check that we have at least one paypent and one delivery module // Find the first availables delivery and payment modules, that's the best we can do. if (null === ModuleQuery::create()->findOneByType(BaseModule::PAYMENT_MODULE_TYPE)) { $error_message = $this->getTranslator()->trans("No active paiement module was found. Please install and activate at least one payment module.", [], ImportT1::DOMAIN); } } if ($error_message !== false) { // Render the edition template. return $this->selectDbAction($error_message); } return $this->generateRedirectFromRoute("importT1.review"); }