Ejemplo n.º 1
0
 /**
  * Return the current database version
  *
  * @return string or false if database doesn't exist
  */
 public function getCurrentVersion()
 {
     $sql = 'SELECT table_name ' . 'FROM information_schema.tables ' . 'WHERE table_name=\'fz_file\'' . '  or  table_name=\'fz_info\'' . '  or  table_name=\'Fichiers\'';
     $res = Fz_Db::findAssocBySQL($sql);
     if (count($res) == 0) {
         return false;
     } else {
         $version = false;
         foreach ($res as $table) {
             if ($table['table_name'] == 'Fichiers') {
                 return '1.2';
                 // TODO add more check
             } else {
                 if ($table['table_name'] == 'fz_file') {
                     $version = '2.0.0';
                 } else {
                     if ($table['table_name'] == 'fz_info') {
                         return Fz_Db::getTable('Info')->getDatabaseVersion();
                     }
                 }
             }
         }
         return $version;
     }
 }
Ejemplo n.º 2
0
 /**
  * Check if we can connect to the database user factory
  *
  */
 public function checkUserFactoryDatabaseConf(&$errors, &$config)
 {
     $oldDb = option('db_conn');
     // save filez db connection
     if (!array_key_exists('db_use_global_conf', $config['user_factory_options']) || $config['user_factory_options']['db_use_global_conf'] == false) {
         try {
             $db = new PDO($config['user_factory_options']['db_server_dsn'], $config['user_factory_options']['db_server_user'], $config['user_factory_options']['db_server_password']);
             $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             $db->exec('SET NAMES \'utf8\'');
             option('db_conn', $db);
         } catch (Exception $e) {
             $errors[] = array('title' => 'Can\'t connect to the user database', 'msg' => $e->getMessage());
         }
     }
     try {
         $sql = 'SELECT * FROM ' . $config['user_factory_options']['db_table'] . ' WHERE ' . $config['user_factory_options']['db_username_field'] . ' LIKE \'%\'' . ' AND   ' . $config['user_factory_options']['db_password_field'] . ' LIKE \'%\'';
         try {
             $result = Fz_Db::findAssocBySQL($sql);
         } catch (Exception $e) {
             $errors[] = array('title' => 'Can\'t fetch data from the user table', 'msg' => $e->getMessage());
         }
     } catch (Exception $e) {
         $errors[] = array('title' => 'Can\'t find the user table', 'msg' => $e->getMessage());
     }
     option('db_conn', $oldDb);
     // restore filez db connection
 }
Ejemplo n.º 3
0
 /**
  * Count the number of users
  * 
  * @return integer number of users
  */
 public function getNumberOfUsers()
 {
     $sql = 'SELECT COUNT(*) AS count FROM ' . $this->getTableName();
     $res = Fz_Db::findAssocBySQL($sql);
     return $res[0]['count'];
 }
Ejemplo n.º 4
0
 /**
  * Tells if filez table 'fz_file' (or 'Fichiers' if Fz1) exists on the
  * configured connection
  *
  * @return boolean
  */
 public function databaseExists()
 {
     $sql = 'SELECT table_name ' . 'FROM information_schema.tables ' . 'WHERE table_name=\'fz_file\'' . '  or  table_name=\'fz_info\'' . '  or  table_name=\'Fichiers\'';
     $res = Fz_Db::findAssocBySQL($sql);
     if (count($res) == 0) {
         return false;
     } else {
         $version = false;
         foreach ($res as $table) {
             if ($table['table_name'] == 'Fichiers') {
                 return '1.2';
                 // TODO add more check
             } else {
                 if ($table['table_name'] == 'fz_file') {
                     $version = '2.0.0';
                 } else {
                     if ($table['table_name'] == 'fz_info') {
                         $res = Fz_Db::findAssocBySQL('SELECT `value` FROM `fz_info` WHERE `key`=\'db_version\'');
                         if (!empty($res)) {
                             return $res[0]['value'];
                         }
                     }
                 }
             }
         }
         return $version;
     }
 }