예제 #1
0
 public static function insertAccessToken($accessToken, $userId, $serviceType)
 {
     if (DropboxFetcher::existsAccessToken($serviceType)) {
         throw new Exception("There is already a Dropbox account connected with chosen service.");
     }
     if (!DropboxFetcher::insertAccessToken($accessToken, $userId, $serviceType)) {
         throw new Exception("No changes made on database. Please try again.");
     }
     return true;
 }
예제 #2
0
     DropboxCon::insertAccessToken($accessTokenExcel, $user->getId(), DropboxCon::SERVICE_APP_EXCEL_BACKUP);
     header('Location: ' . BASE_URL . "cloud/success");
     exit;
 } else {
     if (isBtnRqstTokenDatabaseDropboxKeyPrsd() || isBtnRqstTokenExcelDropboxKeyPrsd()) {
         $authorizeUrl = $webAuth->start();
         header("Location: {$authorizeUrl}");
         exit;
     } else {
         if (isset($_POST['disconnect-dropbox-database-btn'])) {
             DropboxFetcher::disconnectServiceType(DropboxCon::SERVICE_APP_DATABASE_BACKUP);
             header('Location: ' . BASE_URL . "cloud/success");
             exit;
         } else {
             if (isset($_POST['disconnect-dropbox-excel-btn'])) {
                 DropboxFetcher::disconnectServiceType(DropboxCon::SERVICE_APP_EXCEL_BACKUP);
                 header('Location: ' . BASE_URL . "cloud/success");
                 exit;
             } else {
                 if (isBtnRqstDnldDBKeyPrsd()) {
                     date_default_timezone_set('Europe/Athens');
                     $curWorkingDate = new DateTime();
                     $curWorkingHour = intval($curWorkingDate->format('H'));
                     $filePath = ROOT_PATH . 'storage/backups/';
                     $fileName = 'sass_app_db_' . date('m_d_Y_Hi') . '.sql';
                     $zippedFileName = $fileName . '.gz';
                     $fullPathName = $filePath . $fileName;
                     $dumpSettings = array('compress' => Ifsnop\Mysqldump\Mysqldump::GZIP, 'no-data' => false, 'add-drop-table' => true, 'single-transaction' => false, 'lock-tables' => true, 'add-locks' => true, 'extended-insert' => true, 'disable-foreign-keys-check' => true, 'skip-triggers' => false, 'add-drop-trigger' => true, 'databases' => false, 'add-drop-database' => false, 'hex-blob' => true);
                     $dump = new Ifsnop\Mysqldump\Mysqldump(App::getDbName(), App::getDbUsername(), App::getDbPassword(), App::getDbHost(), 'mysql', $dumpSettings);
                     $dump->start($fullPathName);
                     // all credits: http://stackoverflow.com/q/22046020/2790481
# Include the Dropbox SDK libraries
require_once ROOT_PATH . "plugins/dropbox-sdk/lib/Dropbox/autoload.php";
include_once ROOT_PATH . 'plugins/mysqldump-php-1.4.1/src/Ifsnop/Mysqldump/Mysqldump.php';
use Dropbox as dbx;
try {
    date_default_timezone_set('Europe/Athens');
    // run script only during working hours
    if (!App::isWorkingDateTimeOn()) {
        exit;
    }
    $filePath = ROOT_PATH . 'storage/excel/';
    $curTerms = TermFetcher::retrieveCurrTerm();
    foreach ($curTerms as $curTerm) {
        $curTermId = $curTerm[TermFetcher::DB_COLUMN_ID];
        $curTermName = $curTerm[TermFetcher::DB_COLUMN_NAME];
        $curTermStartDateTime = new DateTime($curTerm[TermFetcher::DB_COLUMN_START_DATE]);
        $curTermYear = $curTermStartDateTime->format('Y');
        $fullPathFile = Excel::saveAppointments($curTermId);
        $fileName = pathinfo($fullPathFile)['filename'] . "." . pathinfo($fullPathFile)['extension'];
        $accessToken = DropboxFetcher::retrieveAccessToken(DropboxCon::SERVICE_APP_EXCEL_BACKUP)[DropboxFetcher::DB_COLUMN_ACCESS_TOKEN];
        $dbxClient = new dbx\Client($accessToken, App::getVersion());
        $adminAccountInfo = $dbxClient->getAccountInfo();
        $f = fopen($fullPathFile, "rb");
        $result = $dbxClient->uploadFile("/storage/excel/{$curTermYear}/{$fileName}", dbx\WriteMode::force(), $f);
        fclose($f);
    }
    exit;
} catch (\Exception $e) {
    App::storeError($e);
    exit;
}