public function adminControl()
    {
        $this->disableCaching();
        if (!BackupController::checkForZipSupport()) {
            $this->addToView('no_zip_support', true);
        } else {
            $instance_dao = DAOFactory::getDAO('InstanceDAO');
            if (isset($_POST['instance_id'])) {
                $instance = $instance_dao->get($_POST['instance_id']);
                if ($instance != null) {
                    $this->zip_file_short_name = str_replace(' ', '_', $instance->network_username) . "_" . str_replace(' ', '_', $instance->network) . '_user_data.zip';
                    $this->zip_file_full_name = THINKUP_WEBAPP_PATH . BackupDAO::CACHE_DIR . '/' . $this->zip_file_short_name;
                    $this->readme_file = THINKUP_WEBAPP_PATH . BackupDAO::CACHE_DIR . '/README.txt';
                    $this->files_to_zip[] = array('path' => $this->readme_file, 'name' => 'README.txt');
                    self::appendToReadme('THINKUP EXPORTED USER DATA
===========================

This zip archive contains all the data related to a specific service user gathered by ThinkUp. This README file ' . 'describes how to import that data into an existing ThinkUp installation.

');
                    self::exportData($instance->network_username, $instance->network);
                    self::generateZipFile();
                } else {
                    $this->addErrorMessage('Invalid service user');
                }
            } else {
                //render dropdown and form to get POST['instance_id']
                $owner_dao = DAOFactory::getDAO('OwnerDAO');
                $owner = $owner_dao->getByEmail($this->getLoggedInUser());
                $this->addToView('instances', $instance_dao->getByOwner($owner));
                $this->addInfoMessage('To export and download a single service user\'s data, ' . 'choose a service user and click on the Export User Data button. Extract the zip file ' . 'and refer to the README.txt contained within for instructions on how to import the data ' . 'into another ThinkUp database.');
            }
        }
        return $this->generateView();
    }
    public function adminControl()
    {
        $this->disableCaching();
        if (!BackupController::checkForZipSupport()) {
            $this->addToView('no_zip_support', true);
        } else {
            $instance_dao = DAOFactory::getDAO('InstanceDAO');
            if (isset($_POST['instance_id'])) {
                $instance = $instance_dao->get($_POST['instance_id']);
                if ($instance != null) {
                    $this->zip_file_short_name = str_replace(' ', '_', $instance->network_username) . "_" . str_replace(' ', '_', $instance->network) . '_user_data.zip';
                    $this->zip_file_full_name = FileDataManager::getDataPath($this->zip_file_short_name);
                    $this->readme_file = FileDataManager::getBackupPath('README.txt');
                    $this->files_to_zip[] = array('path' => $this->readme_file, 'name' => 'README.txt');
                    self::appendToReadme('THINKUP EXPORTED USER DATA
===========================

This zip archive contains all the data related to a specific service user gathered by ThinkUp. This README file ' . 'describes how to import that data into an existing ThinkUp installation.

');
                    if (!self::exportData($instance->network_username, $instance->network)) {
                        return $this->generateView();
                    }
                    self::generateZipFile();
                } else {
                    $this->addErrorMessage('Invalid service user');
                }
            } else {
                //render dropdown and form to get POST['instance_id']
                $owner_dao = DAOFactory::getDAO('OwnerDAO');
                $owner = $owner_dao->getByEmail($this->getLoggedInUser());
                $this->addToView('instances', $instance_dao->getByOwner($owner));
                $this->addInfoMessage('Choose a user to export.');
            }
        }
        return $this->generateView();
    }
 public function testMySQLExportFails()
 {
     // backup DAO mapping
     $dao_mapping_backup = DAOFactory::$dao_mapping['BackupDAO'];
     $this->simulateLogin('*****@*****.**', true);
     $controller = new BackupController(true);
     $_GET['backup'] = 'true';
     // no grant perms
     DAOFactory::$dao_mapping['BackupDAO']['mysql'] = 'TestBackupDAOGrantFail';
     $results = $controller->go();
     $this->assertPattern("/It looks like the MySQL user does not have the proper permissions to/", $results);
     // no file perms
     $controller = new BackupController(true);
     DAOFactory::$dao_mapping['BackupDAO']['mysql'] = 'TestBackupDAOFileFail';
     $results = $controller->go();
     $this->assertPattern("/It looks like the MySQL user does not have the proper file permissions/", $results);
     // restore DAO mapping
     DAOFactory::$dao_mapping['BackupDAO']['mysql'] = $dao_mapping_backup;
 }
 public function testResore()
 {
     // create export
     $dao = new BackupMySQLDAO();
     $export_file = $dao->export();
     $this->pdo->query("drop table tu_plugins");
     $this->simulateLogin('*****@*****.**', true);
     $controller = new BackupController(true);
     $_FILES['backup_file']['name'] = "name";
     $_FILES['backup_file']['type'] = "application/zip";
     $_FILES['backup_file']["error"] = 0;
     $_FILES["backup_file"]["tmp_name"] = $export_file;
     $results = $controller->go();
     $this->assertPattern("/Data Import Successfull/is", $results);
     $stmt = $this->pdo->query("show create table tu_plugins");
     $data = $stmt->fetch();
     $stmt->closeCursor();
     $this->assertEqual($data['Table'], 'tu_plugins');
     $stmt = $this->pdo->query("select * from tu_plugins");
     $data = $stmt->fetch();
     $this->assertEqual($data['id'], 1);
     $this->assertEqual($data['name'], 'Twitter');
 }
Example #5
0
            putenv('BACKUP_VERBOSE=true');
            $backup_dao = DAOFactory::getDAO('BackupDAO');
            if ($argv[0] == '--export') {
                print "\nExporting data to: {$filename}\n\n";
                $backup_dao->export($filename);
                print "\nBackup completed...\n\n";
            } else {
                if (!file_exists($filename)) {
                    error_log("\nError: data import file '{$filename}' not found");
                    usage();
                }
                print "\nImporting data from: {$filename}\n\n";
                $backup_dao->import($filename);
                print "\nImport completed...\n\n";
            }
            // release global mutex
            BackupController::mutexLock(true);
        }
    }
} catch (Exception $e) {
    error_log("  Error: " . $e->getMessage() . "\n");
}
function usage()
{
    print "\n Usage:\n\n";
    print "   php backup.php [--help] [--export|--import] filename.zip\n\n";
    print "    --export export_filename.zip - exports data to specified filename\n";
    print "    --import import_filename.zip - imports data from specified filename\n";
    print "    --help                       - usage help\n\n";
    exit;
}
Example #6
0
        $sql = preg_replace('/\\-\\-.*/', '', $migration['sql']);
        $install_dao->runMigrationSQL($sql, $migration['new_migration'], $migration['filename']);
    }
    if (count($migrations) == 0) {
        print "\n  No migrations to run...\n\n";
        exit;
    }
    $option_dao = DAOFactory::getDAO('OptionDAO');
    $option = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, 'database_version');
    if ($option) {
        $option_dao->updateOptionByName(OptionDAO::APP_OPTIONS, 'database_version', $thinkup_db_version);
    } else {
        $option_dao->insertOption(OptionDAO::APP_OPTIONS, 'database_version', $thinkup_db_version);
    }
    // release global mutex
    BackupController::mutexLock();
    // delete upgrade token if it exists
    $upgrade_ctl->deleteTokenFile();
    $upgrade_end_time = microtime(true);
    $total_time = $upgrade_end_time - $upgrade_start_time;
    print "\nUpgrade complete. Total time elapsed: " . round($total_time, 2) . " seconds\n\n";
} catch (Exception $e) {
    error_log("  Error: " . $e->getMessage() . "\n");
}
function usage()
{
    print "\n Usage:\n\n";
    print "   php upgrade.php [--help][--with-new-sql]\n\n";
    print "    --with-new-sql - will upgrade with non-versioned in development sql files\n";
    print "                     example: '2011-05-17_new_feature.sql'\n";
    print "    --help         - usage help\n\n";
 public function testNoZipSupport()
 {
     BackupController::$zip_class_req = 'NoSuchZipArchiveClass';
     $this->simulateLogin('*****@*****.**', true);
     $controller = new ExportServiceUserDataController(true);
     $results = $controller->control();
     $this->assertPattern('/setup does not support a library/', $results);
 }
Example #8
0
/**
 *
 * ThinkUp/webapp/install/backup.php
 *
 * Copyright (c) 2009-2012 Mark Wilkie
 *
 * LICENSE:
 *
 * This file is part of ThinkUp (http://thinkupapp.com).
 *
 * ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
 * later version.
 *
 * ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with ThinkUp.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 *
 * @author Mark Wilkie <mwilkie[at]gmail[dot]com>
 * @license http://www.gnu.org/licenses/gpl.html
 * @copyright 2009-2012 Mark Wilkie
 */
chdir('..');
require_once 'init.php';
$controller = new BackupController();
echo $controller->go();
<?php

include '../LoadClass.php';
$dbhost = 'localhost';
$dbuser = '******';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
$table_name = "reading";
$backup_file = "reading_dump_" . date("Y-m-d-H-i-s") . ".sql";
$sql = "SELECT * INTO OUTFILE '{$backup_file}' FROM {$table_name}";
mysql_select_db('ozious');
$retval = mysql_query($sql, $conn);
if (!$retval) {
    die('Could not take data backup: ' . mysql_error());
}
$readingController = new ReadingController();
$readingController->delete();
$backup = new Backup($backup_file, "Ozious");
$backupController = new BackupController();
$backupController->insert($backup);
echo "Backedup  data successfully\n";
mysql_close($conn);