Пример #1
0
function apply_patch($f)
{
    global $TPL;
    static $files;
    // Should never attempt to apply the same patch twice.. in case
    // there are function declarations in the .php patches.
    if ($files[$f]) {
        return;
    }
    $files[$f] = true;
    $db = new db_alloc();
    $file = basename($f);
    $failed = false;
    $comments = array();
    // This is an important patch that converts money from 120.34 to 12034.
    // We MUST ensure that the user has a currency set before applying this patch.
    if ($file == "patch-00188-alla.sql") {
        if (!config::get_config_item('currency')) {
            alloc_error("No default currency is set! Login to alloc (ignore any errors, you may need to manually change the url to config/config.php after logging in) go to Setup -> Finance and select a Main Currency. And then click the 'Update Transactions That Have No Currency' button. Then return here and apply this patch (patch-188). IT IS REALLY IMPORTANT THAT YOU FOLLOW THESE INSTRUCTIONS as the storage format for monetary amounts has changed.", true);
        }
    }
    // Try for sql file
    if (strtolower(substr($file, -4)) == ".sql") {
        list($sql, $comments) = parse_sql_file($f);
        foreach ($sql as $query) {
            if (!$db->query($query)) {
                #$TPL["message"][] = "<b style=\"color:red\">Error:</b> ".$f."<br>".$db->get_error();
                $failed = true;
                alloc_error("<b style=\"color:red\">Error:</b> " . $f . "<br>" . $db->get_error());
            }
        }
        if (!$failed) {
            $TPL["message_good"][] = "Successfully Applied: " . $f;
        }
        // Try for php file
    } else {
        if (strtolower(substr($file, -4)) == ".php") {
            $str = execute_php_file("../patches/" . $file);
            if ($str && !defined("FORCE_PATCH_SUCCEED_" . $file)) {
                #$TPL["message"][] = "<b style=\"color:red\">Error:</b> ".$f."<br>".$str;
                $failed = true;
                ob_end_clean();
                alloc_error("<b style=\"color:red\">Error:</b> " . $f . "<br>" . $str);
            } else {
                $TPL["message_good"][] = "Successfully Applied: " . $f;
            }
        }
    }
    if (!$failed) {
        $q = prepare("INSERT INTO patchLog (patchName, patchDesc, patchDate) \n                  VALUES ('%s','%s','%s')", $file, implode(" ", $comments), date("Y-m-d H:i:s"));
        $db->query($q);
    }
}
Пример #2
0
$db->verbose = 0;
$q = "CREATE TABLE testCreateTableABC (heyID int)";
$db->query($q);
$cant_create = $db->get_error();
// Try and alter a table to test if we have perm
$db = new db_alloc();
$db->verbose = 0;
$q = "ALTER TABLE testCreateTableABC ADD bee int";
$db->query($q);
$cant_alter = $db->get_error();
// Try and drop a table to test if we have perm
$db = new db_alloc();
$db->verbose = 0;
$q = "DROP TABLE testCreateTableABC";
$db->query($q);
$cant_drop = $db->get_error();
// If we can't do all three, then update the users permissions
if ($cant_create || $cant_drop || $cant_alter) {
    $actions[] = ACTION_FIX_DB_USER_PERMS;
}
$db->verbose = 1;
// Create table patchLog if it doesn't exist
if (!$db->table_exists("patchLog")) {
    $actions[] = ACTION_CREATE_TABLE_PATCHLOG;
}
$commands[ACTION_RM_ALLOC_INC] = "rm -f " . $old_alloc_inc;
$commands[ACTION_CREATE_ALLOC_CONFIG] = "echo '<?php \n" . implode("\n", $newfile) . "\n?>' > " . ALLOC_CONFIG_PATH;
$commands[ACTION_MV_PROJECTS_DIR] = "mv " . ATTACHMENTS_DIR . "projects " . ATTACHMENTS_DIR . "project";
$commands[ACTION_MV_CLIENTS_DIR] = "mv " . ATTACHMENTS_DIR . "clients " . ATTACHMENTS_DIR . "client";
$commands[ACTION_MV_TASKS_DIR] = "mkdir " . ATTACHMENTS_DIR . "task; chmod 777 " . ATTACHMENTS_DIR . "task";
$commands[ACTION_ERR_ATTACHMENTS_DIR_NOT_DEFINED] = "echo 'ERROR: No ATTACHMENTS_DIR defined'";
Пример #3
0
 function restore($archivename)
 {
     global $TPL;
     $file = ATTACHMENTS_DIR . "backups" . DIRECTORY_SEPARATOR . "0" . DIRECTORY_SEPARATOR . $archivename;
     $archive = new PclZip($file);
     # Clear out the folder list
     foreach ($this->folders as $folder) {
         $this->empty_dir(ATTACHMENTS_DIR . $folder);
     }
     $archive->extract(ATTACHMENTS_DIR);
     list($sql, $commends) = parse_sql_file(ATTACHMENTS_DIR . "database.sql");
     $db = new db_alloc();
     foreach ($sql as $q) {
         if (!$db->query($q)) {
             $errors[] = "Error! (" . $db->get_error() . ").";
         }
     }
     is_array($errors) and alloc_error(implode("<br>", $errors));
     unlink(ATTACHMENTS_DIR . "database.sql");
     if (!count($errors)) {
         return true;
     }
 }