Пример #1
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @param  array $filters
  * @return \Pop\Form\Form
  */
 public function setFieldValues(array $values = null, $filters = null)
 {
     parent::setFieldValues($values, $filters);
     if ($_POST) {
         // Check the content directory
         if (!file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . $this->content_path)) {
             $this->getElement('content_path')->addValidator(new Validator\NotEqual($this->content_path, $this->i18n->__('The content directory does not exist.')));
         } else {
             $checkDirs = \Phire\Project::checkDirs($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . $this->content_path, true);
             if (count($checkDirs) > 0) {
                 $this->getElement('content_path')->addValidator(new Validator\NotEqual($this->content_path, $this->i18n->__('The content directory (or subdirectories) are not writable.')));
             }
         }
         // If not SQLite, check the DB parameters
         if (strpos($this->db_adapter, 'Sqlite') === false) {
             $this->getElement('db_name')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database name is required.')));
             $this->getElement('db_username')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database username is required.')));
             $this->getElement('db_password')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database password is required.')));
             $this->getElement('db_host')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database host is required.')));
         }
         // Check the database credentials
         if ($this->isValid()) {
             $oldError = ini_get('error_reporting');
             error_reporting(E_ERROR);
             $dbCheck = Dbs::check(array('database' => $this->db_name, 'username' => $this->db_username, 'password' => $this->db_password, 'host' => $this->db_host, 'type' => str_replace('\\', '_', $this->db_adapter)));
             // If there is a DB error
             if (null != $dbCheck) {
                 $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, wordwrap($dbCheck, 50, '<br />')));
             } else {
                 // Check the database version
                 if (strpos($this->db_adapter, 'Sqlite') === false) {
                     $adapter = stripos($this->db_adapter, 'Pdo\\') !== false ? str_replace('Pdo\\', '', $this->db_adapter) : $this->db_adapter;
                     $db = Db::factory($adapter, array('database' => $this->db_name, 'username' => $this->db_username, 'password' => $this->db_password, 'host' => $this->db_host, 'type' => strtolower(str_replace('Pdo\\', '', $this->db_adapter))));
                     $version = $db->adapter()->version();
                     $version = substr($version, strrpos($version, ' ') + 1);
                     if (strpos($version, '-') !== false) {
                         $version = substr($version, 0, strpos($version, '-'));
                     }
                     if (stripos($this->db_adapter, 'Mysql') !== false) {
                         $dbVerKey = 'Mysql';
                     } else {
                         if (stripos($this->db_adapter, 'Pgsql') !== false) {
                             $dbVerKey = 'Pgsql';
                         } else {
                             $dbVerKey = null;
                         }
                     }
                     if (null !== $dbVerKey && version_compare($version, self::$dbVersions[$dbVerKey]) < 0) {
                         $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, wordwrap($this->i18n->__('The %1 database version must be %2 or greater. (%3 detected.)', array($dbVerKey, self::$dbVersions[$dbVerKey], $version)), 45, '<br />')));
                     }
                 }
             }
             error_reporting($oldError);
         }
     }
     return $this;
 }