Beispiel #1
0
 /**
  * 异步备份数据库
  */
 public function savedbAction()
 {
     set_time_limit(0);
     // 得到所有表
     $db = QP_Db::factory();
     $tabList = $db->fetchCol('show tables');
     // 保存为文件
     $bakfile = SITEWEB_PATH . '/files/dbfiles/' . date('YmdHis') . '.sql';
     $time = date('Y-m-d H:i:s');
     $conter = '-- QuickBug Database Backup' . PHP_EOL;
     $conter .= '-- http://www.vquickbug.com' . PHP_EOL;
     $conter .= "-- Date Time:{$time}" . PHP_EOL . PHP_EOL;
     $conter .= 'SET NAMES UTF8;' . PHP_EOL . PHP_EOL;
     file_put_contents($bakfile, $conter);
     // 备份所有表的数据
     foreach ($tabList as $tab) {
         $conter = '-- --------------------------------------------------------' . PHP_EOL;
         $conter .= '--' . PHP_EOL;
         $conter .= "-- Table Struct `{$tab}`" . PHP_EOL;
         $conter .= '--' . PHP_EOL . PHP_EOL . PHP_EOL;
         // 得到表的结构
         $ret = $db->fetchRow("show create table {$tab}");
         // 过滤  AUTO_INCREMENT=%d
         $conter .= preg_replace('/AUTO_INCREMENT=\\d+/i', '', $ret['Create Table']) . ';' . PHP_EOL . PHP_EOL;
         file_put_contents($bakfile, $conter, FILE_APPEND);
         // 得到表的数据
         $conter = '--' . PHP_EOL;
         $conter .= "-- Table Data `{$tab}`" . PHP_EOL;
         $conter .= '--' . PHP_EOL . PHP_EOL;
         file_put_contents($bakfile, $conter, FILE_APPEND);
         // 将表的数据每100行导一次
         $num = 100;
         $tableCount = $db->count($tab);
         $step = ceil($tableCount / $num);
         for ($i = 0; $i < $step; ++$i) {
             $start = $i * $num;
             $result = $db->select('*', $tab, null, null, "{$start},{$num}");
             // 输出数据
             foreach ($result as $row) {
                 $spr = '';
                 $conter = "INSERT INTO `{$tab}` SET ";
                 foreach ($row as $key => $val) {
                     $conter .= $spr . "`{$key}`=" . $db->escape($val);
                     $spr = ',';
                 }
                 $conter .= ';' . PHP_EOL;
                 file_put_contents($bakfile, $conter, FILE_APPEND);
             }
         }
         $conter = PHP_EOL . PHP_EOL;
         file_put_contents($bakfile, $conter, FILE_APPEND);
     }
     $this->outputJson(0);
 }
Beispiel #2
0
 /**
  * 构造函数
  *
  */
 public function __construct()
 {
     $this->db = QP_Db::factory();
     $this->userid = QP_Session_Session::get('login_userid');
     $this->userpriv = QP_Session_Session::get('login_priv');
 }
Beispiel #3
0
 private function _initTestData()
 {
     $db = QP_Db::factory();
     $time = time();
     // 安装两个用户,一个测试用户,一个开发用户
     $sql = "\r\nINSERT INTO `quickbug_user` (`userid`, `username`, `truename`, `passwd`, `email`, `usertype`, `priv`, `enable`, `dateline`, `ext`) VALUES\r\n(3, 'test', 'Test', 'e10adc3949ba59abbe56e057f20f883e', '*****@*****.**', 1, 1, 1, {$time}, NULL),\r\n(4, 'dev', 'Dev', 'e10adc3949ba59abbe56e057f20f883e', '*****@*****.**', 1, 1, 1, {$time}, NULL)\r\n";
     $db->execute($sql);
     // 组与用户关系
     $sql = "\r\nINSERT INTO `quickbug_groupuser` (`guid`, `groupid`, `userid`) VALUES\r\n(1, 2, 3),\r\n(2, 1, 4)\r\n\t\t";
     $db->execute($sql);
     // 添加一个测试BUG
     $condition = L('bug.condition');
     $step = L('bug.step');
     $case = L('bug.case');
     $interfix_log = L('bug.interfix_log');
     $antic_result = L('bug.antic_result');
     $sql = "\r\nINSERT INTO `quickbug_bugs` (`bugid`, `projectid`, `verid`, `moduleid`, `subject`, `info`, `groupid`, `createuid`, `touserid`, `severity`, `frequency`, `priority`, `bugtype`, `status`, `savetype`, `dateline`, `lastuptime`) VALUES\r\n(1, 1, 1, 1, 'Test Bug', '<p><strong>[{$condition}]</strong> <br />\r\n1: <br />\r\n2: <br />\r\n<br />\r\n<strong>[{$step}]</strong> <br />\r\n1: <br />\r\n2: <br />\r\n<br />\r\n<strong>[{$case}]</strong> <br />\r\n<br />\r\n<br />\r\n<strong>[{$interfix_log}]</strong> <br />\r\n<br />\r\n<br />\r\n<strong>[{$antic_result}]</strong></p>', 1, 3, 4, 3, 1, 3, 1, 1, 1, {$time}, {$time})\r\n\t\t";
     $db->execute($sql);
     // BUG的文档
     $sql = "\r\nINSERT INTO `quickbug_bug_docs` (`bugdocid`, `bugid`, `docname`, `docfile`, `dateline`) VALUES\r\n(1, 1, 'Attachment1', 'attachment1.jpg', {$time})\r\n\t\t";
     // BUG邀请处理记录
     $db->execute($sql);
     $sql = "\r\nINSERT INTO `quickbug_bug_invite` (`inviteid`, `bugid`, `userid`, `ivtuserid`, `opt`, `isread`, `dateline`) VALUES\r\n(1, 1, 3, 4, 0, 0, {$time})\r\n\t\t";
     $db->execute($sql);
     // BUG操作历史记录
     $created_bug = L('bug.created_bug');
     $sql = "\r\nINSERT INTO `quickbug_operate_history` (`id`, `bugid`, `userid`, `text`, `dateline`) VALUES\r\n(1, 1, 3, '{$created_bug}', {$time})\r\n\t\t";
     $db->execute($sql);
 }