Exemplo n.º 1
0
 /**
  * Check if $dbinfo provided the connection details for a Yioop/SeekQuarry
  * database. If it does provide a valid db connection but no data then try
  * to recreate the database from the default copy stored in /data dir.
  *
  * @param array $dbinfo has fields for DBMS, DB_USER, DB_PASSWORD, DB_HOST
  *     and DB_NAME
  * @param array $skip_list an array of table or index names not to bother
  *     creating or copying
  * @return bool returns true if can connect to/create a valid database;
  *     returns false otherwise
  */
 function migrateDatabaseIfNecessary($dbinfo, $skip_list = array())
 {
     $test_dbm = $this->testDatabaseManager($dbinfo);
     if ($test_dbm === false || $test_dbm === true) {
         return $test_dbm;
     }
     $this->initializeSql($test_dbm, $dbinfo);
     $copy_tables = array_diff(array_keys($this->create_statements), $skip_list);
     if (!($create_ok = $this->createDatabaseTables($test_dbm, $dbinfo))) {
         return false;
     }
     require_once BASE_DIR . "/models/datasources/sqlite3_manager.php";
     $default_dbm = new Sqlite3Manager();
     $default_dbm->connect("", "", "", BASE_DIR . "/data/default.db");
     if (!$default_dbm) {
         return false;
     }
     foreach ($copy_tables as $table_or_index) {
         if ($table_or_index != "CURRENT_WEB_INDEX" && stristr($table_or_index, "_INDEX")) {
             continue;
         }
         if (!DatasourceManager::copyTable($table_or_index, $default_dbm, $table_or_index, $test_dbm)) {
             return false;
         }
     }
     if (stristr($dbinfo["DB_HOST"], "pgsql") !== false) {
         /* For postgres count initial values of SERIAL sequences
              will be screwed up unless do
            */
         $auto_tables = array("ACTIVITY" => "ACTIVITY_ID", "GROUP_ITEM" => "GROUP_ITEM_ID", "GROUP_PAGE" => "GROUP_PAGE_ID", "GROUPS" => "GROUP_ID", "LOCALE" => "LOCALE_ID", "ROLE" => "ROLE_ID", "TRANSLATION" => "TRANSLATION_ID", "USERS" => "USER_ID");
         foreach ($auto_tables as $table => $auto_column) {
             $sql = "SELECT MAX({$auto_column}) AS NUM FROM {$table}";
             $result = $test_dbm->execute($sql);
             $row = $test_dbm->fetchArray($result);
             $next = $row['NUM'];
             $sequence = strtolower("{$table}_{$auto_column}_seq");
             $sql = "SELECT setval('{$sequence}', {$next})";
             $test_dbm->execute($sql);
         }
     }
     return true;
 }
Exemplo n.º 2
0
/**
 * Reads the Help articles from default db and returns the array of pages.
 */
function getWikiHelpPages()
{
    $help_pages = array();
    require_once BASE_DIR . "/models/datasources/sqlite3_manager.php";
    $default_dbm = new Sqlite3Manager();
    $default_dbm->connect("", "", "", BASE_DIR . "/data/default.db");
    if (!$default_dbm) {
        return false;
    }
    $group_model = new GroupModel(DB_NAME, true);
    $group_model->db = $default_dbm;
    $page_list = $group_model->getPageList(HELP_GROUP_ID, "en-US", '', 0, 200);
    foreach ($page_list[1] as $page) {
        if (isset($page['TITLE'])) {
            $page_info = $group_model->getPageInfoByName(HELP_GROUP_ID, $page['TITLE'], "en-US", "api");
            $page_content = str_replace("&", "&", $page_info['PAGE']);
            $page_content = html_entity_decode($page_content, ENT_QUOTES, "UTF-8");
            $help_pages[$page['TITLE']] = $page_content;
        }
    }
    return $help_pages;
}