OSDN Git Service

PDO対応
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / backup.php
index e84d455..4884da0 100755 (executable)
@@ -73,7 +73,7 @@ class Backup
                // catch all output generated by plugins\r
                ob_start();\r
                $res = sql_query('SELECT pfile FROM '.sql_table('plugin'));\r
-               while ($plugName = mysql_fetch_object($res)) {\r
+               while ($plugName = sql_fetch_object($res)) {\r
                        $plug =& $manager->getPlugin($plugName->pfile);\r
                        if ($plug) $tables = array_merge($tables, (array) $plug->getTableList());\r
                }\r
@@ -108,14 +108,14 @@ class Backup
                \r
                // dump header\r
                echo "#\n";\r
-               echo "# This is a backup file generated by Nucleus \n";\r
-               echo "# http://www.nucleuscms.org/\n";\r
+               echo "# " . _BACKUP_BACKUPFILE_TITLE . " \n";\r
+               echo "# " . _ADMINPAGEFOOT_OFFICIALURL . "\n";\r
                echo "#\n";\r
-               echo "# backup-date: " .  gmdate("d-m-Y H:i:s", time()) . " GMT\n";\r
+               echo "# " . _BACKUP_BACKUPFILE_BACKUPDATE .  gmdate("d-m-Y H:i:s", time()) . " GMT\n";\r
                global $nucleus;\r
-               echo "# Nucleus CMS version: " . $nucleus['version'] . "\n";\r
+               echo "# " . _BACKUP_BACKUPFILE_NUCLEUSVERSION . $nucleus['version'] . "\n";\r
                echo "#\n";\r
-               echo "# WARNING: Only try to restore on servers running the exact same version of Nucleus\n";\r
+               echo "# " . _BACKUP_WARNING_NUCLEUSVERSION . "\n";\r
                echo "#\n";\r
                \r
                // dump all tables\r
@@ -142,7 +142,7 @@ class Backup
        function _backup_dump_table($tablename, $key) {\r
        \r
                echo "#\n";\r
-               echo "# TABLE: " . $tablename . "\n";\r
+               echo "# " . _BACKUP_BACKUPFILE_TABLE_NAME . $tablename . "\n";\r
                echo "#\n";\r
        \r
                // dump table structure\r
@@ -159,6 +159,20 @@ class Backup
        \r
                // add command to drop table on restore\r
                echo "DROP TABLE IF EXISTS $tablename;\n";\r
+               $result = sql_query("SHOW CREATE TABLE $tablename");\r
+               $create = sql_fetch_assoc($result);\r
+               echo $create['Create Table'];\r
+               echo ";\n\n";\r
+       }\r
+\r
+       /**\r
+         * Creates a dump of the table structure for one table\r
+         */\r
+/* replaced by code above in 3.5\r
+       function _backup_dump_structure($tablename) {\r
+       \r
+               // add command to drop table on restore\r
+               echo "DROP TABLE IF EXISTS $tablename;\n";\r
                echo "CREATE TABLE $tablename(\n";\r
        \r
                //\r
@@ -221,6 +235,7 @@ class Backup
        \r
                echo "\n);\n\n";\r
        }\r
+*/\r
 \r
        /**\r
         * Returns the field named for the given table in the \r
@@ -240,7 +255,7 @@ class Backup
        \r
                        $fields = array();\r
                        for ($j = 0; $j < $num_fields; $j++) {\r
-                               $fields[] = mysql_field_name($result, $j);\r
+                               $fields[] = sql_field_name($result, $j);\r
                        }\r
        \r
        /*      }*/\r
@@ -255,12 +270,12 @@ class Backup
                //\r
                // Grab the data from the table.\r
                //\r
-               $result = mysql_query("SELECT * FROM $tablename");\r
+               $result = sql_query("SELECT * FROM $tablename");\r
        \r
-               if(mysql_num_rows($result) > 0)\r
-                       echo "\n#\n# Table Data for $tablename\n#\n";\r
+               if(sql_num_rows($result) > 0)\r
+                       echo "\n#\n# " . sprintf(_BACKUP_BACKUPFILE_TABLEDATAFOR, $tablename) . "\n#\n";\r
                        \r
-               $num_fields = mysql_num_fields($result);\r
+               $num_fields = sql_num_fields($result);\r
                \r
                //\r
                // Compose fieldname list\r
@@ -270,7 +285,7 @@ class Backup
                //\r
                // Loop through the resulting rows and build the sql statement.\r
                //\r
-               while ($row = mysql_fetch_array($result))\r
+               while ($row = sql_fetch_array($result))\r
                {\r
                        // Start building the SQL statement.\r
        \r
@@ -325,19 +340,19 @@ class Backup
        \r
                // first of all: get uploaded file:\r
                if (empty($uploadInfo['name']))\r
-                       return 'No file uploaded';\r
+                       return _BACKUP_RESTOR_NOFILEUPLOADED;\r
                if (!is_uploaded_file($uploadInfo['tmp_name']))\r
-                       return 'No file uploaded';\r
+                       return _BACKUP_RESTOR_NOFILEUPLOADED;\r
        \r
                $backup_file_name = $uploadInfo['name'];\r
                $backup_file_tmpname = $uploadInfo['tmp_name'];\r
                $backup_file_type = $uploadInfo['type'];\r
        \r
                if (!file_exists($backup_file_tmpname))\r
-                       return 'File Upload Error';\r
+                       return _BACKUP_RESTOR_UPLOAD_ERROR;\r
        \r
                if (!preg_match("/^(text\/[a-zA-Z]+)|(application\/(x\-)?gzip(\-compressed)?)|(application\/octet-stream)$/is", $backup_file_type) )\r
-                       return 'The uploaded file is not of the correct type';\r
+                       return _BACKUP_RESTOR_UPLOAD_NOCORRECTTYPE;\r
        \r
        \r
                if (preg_match("/\.gz/is",$backup_file_name))\r
@@ -346,7 +361,7 @@ class Backup
                        $gzip = 0;\r
        \r
                if (!extension_loaded("zlib") && $gzip)\r
-                       return "Cannot decompress gzipped backup (zlib package not installed)";\r
+                       return _BACKUP_RESTOR_UPLOAD_NOZLIB;\r
        \r
                // get sql query according to gzip setting (either decompress, or not)\r
                if($gzip)\r
@@ -389,8 +404,8 @@ class Backup
                                // DEBUG\r
        //                      debug("Executing: " . htmlspecialchars($sql) . "\n");\r
        \r
-                               $result = mysql_query($sql);\r
-                               if (!$result) debug('SQL Error: ' . mysql_error());\r
+                               $result = sql_query($sql);\r
+                               if (!$result) debug(_BACKUP_RESTOR_SQL_ERROR . sql_error());\r
        \r
                        }\r
                }\r