/**
  * Destroy Config, Webapp, $_SESSION, $_POST, $_GET, $_REQUEST
  */
 public function tearDown()
 {
     Config::destroyInstance();
     Webapp::destroyInstance();
     Crawler::destroyInstance();
     if (isset($_SESSION)) {
         $this->unsetArray($_SESSION);
     }
     $this->unsetArray($_POST);
     $this->unsetArray($_GET);
     $this->unsetArray($_REQUEST);
     $this->unsetArray($_SERVER);
     $this->unsetArray($_FILES);
     Loader::unregister();
     $backup_dir = FileDataManager::getBackupPath();
     if (file_exists($backup_dir)) {
         try {
             @exec('cd ' . $backup_dir . '; rm -rf *');
             rmdir($backup_dir);
             // won't delete if has files
         } catch (Exception $e) {
         }
     }
     $data_dir = FileDataManager::getDataPath();
     if (file_exists($data_dir . 'compiled_view')) {
         try {
             @exec('cd ' . $data_dir . '; rm -rf compiled_view');
         } catch (Exception $e) {
         }
     }
     parent::tearDown();
 }
 private function deleteFile($file)
 {
     $file = FileDataManager::getBackupPath($file);
     if (file_exists($file)) {
         unlink($file);
     }
 }
Exemplo n.º 3
0
 public function setUp()
 {
     parent::setUp();
     new BackupMySQLDAO();
     $this->config = Config::getInstance();
     $this->pdo = BackupMySQLDAO::$PDO;
     $this->backup_file = FileDataManager::getDataPath('.htthinkup_db_backup.zip');
     $this->backup_test = FileDataManager::getDataPath('thinkup_db_backup_test.zip');
     $this->backup_dir = FileDataManager::getBackupPath() . '/';
 }
Exemplo n.º 4
0
 public function testGetBackupPath()
 {
     require THINKUP_WEBAPP_PATH . 'config.inc.php';
     //if test fails here, the config file doesn't have datadir_path set
     $this->assertNotNull($THINKUP_CFG['datadir_path']);
     //test just path
     $path = FileDataManager::getBackupPath();
     $this->assertEqual($path, $THINKUP_CFG['datadir_path'] . 'backup/');
     //test just path
     $path = FileDataManager::getBackupPath('README.txt');
     $this->assertEqual($path, $THINKUP_CFG['datadir_path'] . 'backup/README.txt');
 }
Exemplo n.º 5
0
 public function tearDown()
 {
     parent::tearDown();
     $zipfile = FileDataManager::getBackupPath('.htthinkup_db_backup.zip');
     $backup_dir = FileDataManager::getBackupPath();
     if (file_exists($zipfile)) {
         unlink($zipfile);
     }
     if (file_exists($backup_dir)) {
         $this->recursiveDelete($backup_dir);
     }
 }
Exemplo n.º 6
0
 public function testExportToFile()
 {
     $posts_table_file = FileDataManager::getBackupPath('posts.tmp');
     $links_table_file = FileDataManager::getBackupPath('links.tmp');
     $users_table_file = FileDataManager::getBackupPath('users.tmp');
     if (file_exists($posts_table_file)) {
         unlink($posts_table_file);
     }
     if (file_exists($links_table_file)) {
         unlink($links_table_file);
     }
     if (file_exists($users_table_file)) {
         unlink($users_table_file);
     }
     $this->assertFalse(file_exists($posts_table_file));
     $this->assertFalse(file_exists($users_table_file));
     $this->assertFalse(file_exists($links_table_file));
     $this->dao->exportPostsLinksUsersToFile($posts_table_file, $links_table_file, $users_table_file);
     $this->assertTrue(file_exists($posts_table_file));
     $this->assertTrue(file_exists($users_table_file));
     $this->assertTrue(file_exists($links_table_file));
 }
 protected function exportCountHistory($user_id, $network)
 {
     //just the max of each day's count
     $count_history_table_file = FileDataManager::getBackupPath('count_history.tmp');
     $export_dao = DAOFactory::getDAO('ExportDAO');
     $export_dao->exportCountHistoryToFile($user_id, $network, $count_history_table_file);
     $this->files_to_zip[] = array('path' => $count_history_table_file, 'name' => 'count_history.tmp');
     $import_instructions = "LOAD DATA INFILE '/your/path/to/count_history.tmp' ";
     $import_instructions .= "IGNORE INTO TABLE tu_count_history;\n\n";
     self::appendToReadme($import_instructions);
 }
Exemplo n.º 8
0
 public function export($backup_file = null)
 {
     // get table names...
     $q = "show tables";
     $q2 = "show create table ";
     $stmt = $this->execute($q);
     $data = $this->getDataRowsAsArrays($stmt);
     $create_tables = '';
     $zip_file = FileDataManager::getDataPath('.htthinkup_db_backup.zip');
     if ($backup_file) {
         $zip_file = $backup_file;
     }
     $zip = new ZipArchive();
     if (file_exists($zip_file)) {
         unlink($zip_file);
     }
     // make sure w can create this zip file, ZipArchive is a little funky and wont let us know its status
     // until we call close
     $zip_create_status = @touch($zip_file);
     if ($zip_create_status) {
         unlink($zip_file);
     }
     $backup_dir = FileDataManager::getBackupPath();
     if (!$zip_create_status || $zip->open($zip_file, ZIPARCHIVE::CREATE) !== TRUE) {
         throw new Exception("Unable to open backup file for exporting: {$zip_file}");
     }
     // write lock tables...
     $table_locks_list = '';
     foreach ($data as $table) {
         foreach ($table as $key => $value) {
             if ($table_locks_list != '') {
                 $table_locks_list .= ', ';
             }
             $table_locks_list .= $value . ' WRITE';
         }
     }
     try {
         $stmt = $this->execute("LOCK TABLES " . $table_locks_list);
         $tmp_table_files = array();
         foreach ($data as $table) {
             foreach ($table as $key => $value) {
                 if (getenv('BACKUP_VERBOSE') !== false) {
                     print "  Backing up data for table: {$value}\n";
                 }
                 $stmt = $this->execute($q2 . $value);
                 $create_tables .= "-- Create {$value} table statement\n";
                 $create_tables .= "DROP TABLE IF EXISTS {$value};\n";
                 $create_data = $this->getDataRowAsArray($stmt);
                 $create_tables .= $create_data["Create Table"] . ";";
                 $create_tables .= "\n\n";
                 // export table data
                 $table_file = FileDataManager::getBackupPath($value . '.txt');
                 if (file_exists($table_file)) {
                     unlink($table_file);
                 }
                 $q3 = "select * INTO OUTFILE '{$table_file}' from {$value}";
                 $stmt = $this->execute($q3);
                 $zip->addFile($table_file, "/{$value}" . '.txt');
                 array_push($tmp_table_files, $table_file);
             }
         }
     } catch (Exception $e) {
         $err = $e->getMessage();
         if (preg_match("/Can't create\\/write to file/", $err) || preg_match("/Can\\'t get stat of/", $err)) {
             // a file perm issue?
             throw new OpenFileException("It looks like the MySQL user does not have the proper file permissions " . "to back up data");
         } else {
             // assume its a GRANT FILE OR LOCK TABLES issue?
             throw new MySQLGrantException("It looks like the MySQL user does not have the proper grant permissions " . "to back up data");
         }
         error_log("export DB OUTFILE error: " . $e->getMessage());
     }
     // unlock tables...
     $stmt = $this->execute("unlock tables");
     if (getenv('BACKUP_VERBOSE') !== false) {
         print "\n  Backing up create table statments\n";
     }
     $zip->addFromString("create_tables.sql", $create_tables);
     $zip_close_status = $zip->close();
     // clean up tmp table files
     foreach ($tmp_table_files as $tmp_file) {
         unlink($tmp_file);
     }
     if ($zip_close_status == false) {
         throw new Exception("Unable to create backup file for exporting. Bad file path?: {$zip_file}");
     }
     return $zip_file;
 }