/** * Dump osclass database into path file * * @param type $path * @param type $file * @return type */ function osc_dbdump($path, $file) { require_once LIB_PATH . 'osclass/model/Dump.php'; if (!is_writable($path)) { return -4; } if ($path == '') { return -1; } //checking connection $dump = Dump::newInstance(); if (!$dump) { return -2; } $path .= $file; $result = $dump->showTables(); if (!$result) { $_str = ''; $_str .= '/* no tables in ' . DB_NAME . ' */'; $_str .= "\n"; $f = fopen($path, "a"); fwrite($f, $_str); fclose($f); return -3; } $_str = ''; $_str .= '/* OSCLASS MYSQL Autobackup (' . date('Y-m-d H:i:s') . ') */'; $_str .= "\n"; $f = fopen($path, "a"); fwrite($f, $_str); fclose($f); $tables = array(); foreach ($result as $_table) { $tableName = current($_table); $tables[$tableName] = $tableName; } $tables_order = array('t_locale', 't_country', 't_currency', 't_region', 't_city', 't_city_area', 't_widget', 't_admin', 't_user', 't_user_description', 't_category', 't_category_description', 't_category_stats', 't_item', 't_item_description', 't_item_location', 't_item_stats', 't_item_resource', 't_item_comment', 't_preference', 't_user_preferences', 't_pages', 't_pages_description', 't_plugin_category', 't_cron', 't_alerts', 't_keywords', 't_meta_fields', 't_meta_categories', 't_item_meta'); // Backup default OSClass tables in order, so no problem when importing them back foreach ($tables_order as $table) { if (array_key_exists(DB_TABLE_PREFIX . $table, $tables)) { $dump->table_structure($path, DB_TABLE_PREFIX . $table); $dump->table_data($path, DB_TABLE_PREFIX . $table); unset($tables[DB_TABLE_PREFIX . $table]); } } // Backup the rest of tables foreach ($tables as $table) { $dump->table_structure($path, $table); $dump->table_data($path, $table); } return 1; }