/** * Update the database schema to the latest version */ public function migrate() { $sql = ''; $version = $this->getCurrentVersion(); if ($version === false) { $sql = file_get_contents($this->_dbFilesRootDir . '/schema.sql'); } else { $pattern = '/filez-(([0-9]*)\\.([0-9]*)\\.([0-9]*)-([0-9]*))\\.sql$/'; $matches = array(); foreach ($this->getMigrationScripts() as $file) { $matches = array(); if (preg_match($pattern, $file, $matches) === 1) { if (strcmp($matches[1], $version) > 0) { $sql .= file_get_contents($file); } } } // Update filez version if (!empty($sql)) { $sql .= 'UPDATE `fz_info` SET `value`=\'' . $matches[1] . '\' WHERE `key`=\'db_version\''; } } if (!empty($sql)) { Fz_Db::getConnection()->exec($sql); } }
/** * Function used to encrypt the password * * @param string password */ public function setPassword($password) { $algorithm = fz_config_get('user_factory_options', 'db_password_algorithm'); $this->password = $password; $sql = null; if ($algorithm === null) { $sql = 'SHA1(CONCAT(:salt,:password))'; $this->_updatedColumns[] = 'salt'; // to force PDO::bindValue when updating } else { if ($algorithm == 'MD5') { $sql = 'MD5(:password)'; } else { if ($algorithm == 'SHA1') { $sql = 'SHA1(:password)'; } else { if (is_callable($algorithm)) { if (strstr($algorithm, '::') !== false) { $algorithm = explode('::', $algorithm); } $sql = Fz_Db::getConnection()->quote(call_user_func($algorithm, $password)); } else { $sql = $algorithm; // Plain SQL } } } } if ($sql !== null) { $this->setColumnModifier('password', $sql); } }
/** * Method used to get a value for a specified key. * * @param string $key * @return string or false if the key wasn't found */ public function get($key) { $db = Fz_Db::getConnection(); $sql = 'SELECT `value` FROM `' . $this->getTableName() . '` WHERE `fz_info`.`key` = ?'; $stmt = $db->prepare($sql); $stmt->execute(array($key)); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $result ? $result['value'] : false; }