Esempio n. 1
0
 /**
  * Remove nested patches within this patch. 
  *  
  * @param Bouda\Php7Backport\Patch
  */
 private function removeNestedPatches(Patch $patch)
 {
     $start = $patch->getStartPosition();
     $end = $patch->getOriginalEndPosition();
     if ($start == $end) {
         return;
     }
     // delete all patches starting between the start and end of this patch
     $keysToDelete = array_flip(range($start + 1, $end));
     $this->replacePatches = array_diff_key($this->replacePatches, $keysToDelete);
 }
 public function testApply()
 {
     $this->m->setDistance(1000);
     $this->m->setThreshold(0.5);
     $this->p->setDeleteTreshold(0.5);
     // Null case.
     $patches = $this->p->make("", "");
     $this->assertEquals(array("Hello world.", array()), $this->p->apply($patches, "Hello world."));
     // Exact match.
     $patches = $this->p->make("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.");
     $this->assertEquals(array("That quick brown fox jumped over a lazy dog.", array(true, true)), $this->p->apply($patches, "The quick brown fox jumps over the lazy dog."));
     // Partial match.
     $this->assertEquals(array("That quick red rabbit jumped over a tired tiger.", array(true, true)), $this->p->apply($patches, "The quick red rabbit jumps over the tired tiger."));
     // Failed match.
     $this->assertEquals(array("I am the very model of a modern major general.", array(false, false)), $this->p->apply($patches, "I am the very model of a modern major general."));
     // Big delete, small change.
     $patches = $this->p->make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
     $this->assertEquals(array("xabcy", array(true, true)), $this->p->apply($patches, "x123456789012345678901234567890-----++++++++++-----123456789012345678901234567890y"));
     // Big delete, big change 1.
     $patches = $this->p->make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
     $this->assertEquals(array("xabc12345678901234567890---------------++++++++++---------------12345678901234567890y", array(false, true)), $this->p->apply($patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y"));
     // Big delete, big change 2.
     $this->p->setDeleteTreshold(0.6);
     $patches = $this->p->make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
     $this->assertEquals(array("xabcy", array(true, true)), $this->p->apply($patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y"));
     $this->p->setDeleteTreshold(0.5);
     // Compensate for failed patch.
     $this->m->setDistance(0);
     $this->m->setThreshold(0.0);
     $patches = $this->p->make("abcdefghijklmnopqrstuvwxyz--------------------1234567890", "abcXXXXXXXXXXdefghijklmnopqrstuvwxyz--------------------1234567YYYYYYYYYY890");
     $this->assertEquals(array("ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567YYYYYYYYYY890", array(false, true)), $this->p->apply($patches, "ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567890"));
     $this->m->setDistance(1000);
     $this->m->setThreshold(0.5);
     // No side effects.
     $patches = $this->p->make("", "test");
     $patchesText = $this->p->toText($patches);
     $this->p->apply($patches, "");
     $this->assertEquals($patchesText, $this->p->toText($patches));
     // No side effects with major delete.
     $patches = $this->p->make("The quick brown fox jumps over the lazy dog.", "Woof");
     $patchesText = $this->p->toText($patches);
     $this->p->apply($patches, "The quick brown fox jumps over the lazy dog.");
     $this->assertEquals($patchesText, $this->p->toText($patches));
     // Edge exact match.
     $patches = $this->p->make("", "test");
     $this->assertEquals(array("test", array(true)), $this->p->apply($patches, ""));
     // Near edge exact match.
     $patches = $this->p->make("XY", "XtestY");
     $this->assertEquals(array("XtestY", array(true)), $this->p->apply($patches, "XY"));
     // Edge partial match.
     $patches = $this->p->make("y", "y123");
     $this->assertEquals(array("x123", array(true)), $this->p->apply($patches, "x"));
 }
Esempio n. 3
0
 private function _apply_patch()
 {
     $patch = $this->request->post('patch');
     try {
         Patch::apply($patch);
     } catch (Validation_Exception $ex) {
         Messages::errors($ex->errors());
     } catch (Kohana_Exception $ex) {
         Messages::errors($ex->getMessage());
     }
     $this->go_back();
 }
Esempio n. 4
0
<?php

include "../patches.php";
$patch = new Patch(18);
if (!$patch->exists()) {
    $createSql = "CREATE TABLE IF NOT EXISTS `webcam_images` (\n\t\t\t  `timestamp` datetime NOT NULL,\n\t\t\t  `image_id` bigint(11) unsigned NOT NULL,\n\t\t\t  `user_id` int(11) unsigned NOT NULL,\n\t\t\t  `bot_id` int(11) unsigned NULL,\n\t\t\t  `job_id` int(11) unsigned NULL,\n\t\t\t  PRIMARY KEY (`timestamp`, `image_id`),\n\t\t\t  FOREIGN KEY (`image_id`) REFERENCES s3_files(`id`) ON DELETE CASCADE,\n\t\t\t  FOREIGN KEY (`user_id`) REFERENCES users(`id`) ON DELETE CASCADE,\n\t\t\t  FOREIGN KEY (`bot_id`) REFERENCES bots(`id`) ON DELETE CASCADE,\n\t\t\t  FOREIGN KEY (`job_id`) REFERENCES jobs(`id`) ON DELETE CASCADE\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
    db()->execute($createSql);
    $failCount = 0;
    $rowSql = "SELECT id from jobs where webcam_images!=''";
    $jobsCollection = new Collection($rowSql);
    $jobsCollection->bindType('id', 'Job');
    $jobs = $jobsCollection->getAll();
    $total = $jobsCollection->count();
    $count = 0;
    $patch->progress(0);
    // Get the current webcam images in an array, so we can quickly skip those.
    $pdoStatement = db()->query("SELECT image_id from webcam_images");
    $existingImages = array();
    foreach ($pdoStatement->fetchAll(PDO::FETCH_ASSOC) as $row) {
        $existingImages[$row['image_id']] = true;
    }
    foreach ($jobs as $row) {
        /** @var Job $job */
        $job = $row['Job'];
        $images_json = $job->get('webcam_images');
        if ($job->isHydrated() && $images_json != "") {
            $images = json_decode($images_json, true);
            $rowData = array();
            foreach ($images as $timestamp => $image_id) {
                if (!array_key_exists($image_id, $existingImages)) {
                    $file = Storage::get($image_id);
Esempio n. 5
0
<?php

include "../patches.php";
$patch = new Patch(20);
if (!$patch->exists()) {
    $emptySql = "SELECT count(id) FROM s3_files WHERE add_date='0000-00-00 00:00:00'";
    $originalCount = db()->getValue($emptySql);
    $patch->log("Starting with {$originalCount} files with invalid dates.");
    // Fix known images
    $sql = "UPDATE s3_files, webcam_images\n\t\t\tSET s3_files.add_date=webcam_images.timestamp\n\t\t\tWHERE s3_files.id = webcam_images.image_id\n\t\t\tAND s3_files.add_date='0000-00-00 00:00:00'";
    $currentCount = fix_timestamp($sql, "Known image timestamps", $originalCount);
    // Fix gcode files uploaded directly
    $sql = "UPDATE s3_files, jobs\n\t\t\tSET s3_files.add_date=jobs.created_time\n\t\t\tWHERE jobs.source_file_id=s3_files.id\n\t\t\tAND s3_files.add_date='0000-00-00 00:00:00'";
    $currentCount = fix_timestamp($sql, "Known gcode files", $currentCount);
    // Fix gcode files made by a slicer
    $sql = "UPDATE s3_files, jobs, slice_jobs\n\t\t\tSET s3_files.add_date=slice_jobs.finish_date\n\t\t\tWHERE jobs.id=slice_jobs.job_id\n\t\t\tAND slice_jobs.input_id=jobs.source_file_id\n\t\t\tAND slice_jobs.output_id=jobs.file_id\n            AND s3_files.id=jobs.file_id\n\t\t\tAND slice_jobs.finish_date!='0000-00-00 00:00:00'\n\t\t\tAND s3_files.add_date='0000-00-00 00:00:00'";
    $currentCount = fix_timestamp($sql, "Sliced gcode files", $currentCount);
    // Fix files if a child has a timestamp, but the parent doesn't.
    $sql = "UPDATE s3_files a, s3_files b\n\t\t\tSET a.add_date=b.add_date\n\t\t\tWHERE a.id=b.parent_id\n\t\t\tAND b.parent_id!=0\n\t\t\tAND b.add_date!='0000-00-00 00:00:00'\n\t\t\tAND a.add_date='0000-00-00 00:00:00'";
    $currentCount = fix_timestamp($sql, "Fixing parent files", $currentCount);
    // Fix files if a parent has a timestamp, but the child doesn't.
    $sql = "UPDATE s3_files a, s3_files b\n\t\t\tSET a.add_date=b.add_date\n\t\t\tWHERE a.parent_id=b.id\n\t\t\tAND a.parent_id!=0\n\t\t\tAND b.add_date!='0000-00-00 00:00:00'\n\t\t\tAND a.add_date='0000-00-00 00:00:00'";
    $currentCount = fix_timestamp($sql, "Fixing child files", $currentCount);
    $patch->log("Total: " . ($originalCount - $currentCount) . " fixed, {$currentCount} remaining");
    $patch->finish("Fixing bad timestamps for s3_files");
}
function fix_timestamp($sql, $method, $lastCount)
{
    global $patch, $emptySql;
    db()->execute($sql);
    $currentCount = db()->getValue($emptySql);
Esempio n. 6
0
<?php

include "../patches.php";
$patch = new Patch(5);
if (!$patch->exists()) {
    $addContentIDKey = "ALTER TABLE comments ADD KEY `content_id` (`content_id`)";
    db()->execute($addContentIDKey);
    $addContentTypeKey = "ALTER TABLE comments ADD KEY `content_type` (`content_type`)";
    db()->execute($addContentTypeKey);
    $addWebcamID = "ALTER TABLE jobs ADD COLUMN `webcam_image_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' AFTER verified_time;";
    db()->execute($addWebcamID);
    $addWebcamImages = "ALTER TABLE jobs ADD COLUMN `webcam_images` TEXT NOT NULL AFTER webcam_image_id";
    db()->execute($addWebcamImages);
    $dropTimestamp = "ALTER TABLE oauth_consumer_nonce DROP INDEX timestamp";
    db()->execute($dropTimestamp);
    $dropNonce = "ALTER TABLE oauth_consumer_nonce DROP INDEX nonce";
    db()->execute($dropNonce);
    $addIPAddressKey = "ALTER TABLE oauth_token ADD KEY `ip_address` (`ip_address`)";
    db()->execute($addIPAddressKey);
    $addParentIDKey = "ALTER TABLE s3_files ADD KEY `parent_id` (`parent_id`)";
    db()->execute($addParentIDKey);
    $modifyThingiverseToken = "ALTER TABLE users MODIFY `thingiverse_token` VARCHAR(40) NOT NULL DEFAULT ''";
    db()->execute($modifyThingiverseToken);
    $modifyThumbnail = "ALTER TABLE users MODIFY `dashboard_style` ENUM('list','large_thumbnails','medium_thumbnails','small_thumbnails') NOT NULL DEFAULT 'large_thumbnails'";
    db()->execute($modifyThumbnail);
    $patch->finish("Updating the dev table to BotQueue production");
}
Esempio n. 7
0
<?php

include "../patches.php";
$patch = new Patch(12);
if (!$patch->exists()) {
    // Fix the temperature fields:
    $rs = db()->query("SELECT * from jobs");
    while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
        $job = new Job($row['id']);
        $fixed_data = fix_temp_data($job->get('temperature_data'));
        $job->set('temperature_data', $fixed_data);
        $job->save();
    }
    $rs = db()->query("SELECT * from bots");
    while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
        $bot = new Bot($row['id']);
        $fixed_data = fix_temp_data($bot->get('temperature_data'));
        $bot->set('temperature_data', $fixed_data);
        $bot->save();
    }
    $expandTemperatureData = "\n\t\tALTER TABLE jobs\n  \t\tMODIFY COLUMN temperature_data longtext NOT NULL";
    db()->execute($expandTemperatureData);
    $expandTemperatureData = "\n\t\tALTER TABLE bots\n  \t\tMODIFY COLUMN temperature_data longtext NOT NULL";
    $patch->finish("Expanded temperature data fields");
}
function fix_temp_data($data)
{
    if (strlen($data) == 0) {
        return "";
    }
    $data .= "}";
Esempio n. 8
0
<?php

include "../patches.php";
$patch = new Patch(10);
if (!$patch->exists()) {
    $statsViewSQL = "\n        CREATE VIEW stats AS\n        SELECT (unix_timestamp(end_date) - unix_timestamp(start_date)) AS seconds,\n        bot_id, user_id, status, start_date, end_date\n        FROM job_clock\n        WHERE status != 'working'\n        ORDER by seconds DESC\n    ";
    db()->execute($statsViewSQL);
    $patch->finish("Adding stats view");
}
Esempio n. 9
0
<?php

include "../patches.php";
$patch = new Patch(11);
if (!$patch->exists()) {
    $addDroppedSQL = "ALTER TABLE job_clock\n  \t\tMODIFY COLUMN status\n  \t\tenum('working','waiting', 'complete', 'dropped')";
    db()->execute($addDroppedSQL);
    $patch->finish("Changing job_clock enum");
}
Esempio n. 10
0
<?php

include "../patches.php";
$patch = new Patch(14);
if (!$patch->exists()) {
    $sql = "CREATE TABLE IF NOT EXISTS `bot_queues` (\n\t\t        `queue_id` INT(11) UNSIGNED NOT NULL,\n\t\t        `bot_id` INT(11) UNSIGNED NOT NULL,\n\t\t        `priority` INT(11) UNSIGNED NOT NULL,\n\t\t        PRIMARY KEY (`queue_id`, `bot_id`, `priority`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8";
    db()->execute($sql);
    $sql = "SELECT id, queue_id from bots";
    $bots = new Collection($sql);
    $bots->bindType("id", "Bot");
    $bots->bindType("queue_id", "Queue");
    foreach ($bots->getAll() as $row) {
        $bot = $row['Bot'];
        $queue = $row['Queue'];
        $sql = "INSERT INTO bot_queues VALUES(?, ?, 1)";
        $data = array($queue->id, $bot->id);
        db()->execute($sql, $data);
    }
    $sql = "DROP INDEX queue_id ON bots";
    db()->execute($sql);
    $sql = "ALTER TABLE bots DROP COLUMN queue_id";
    db()->execute($sql);
    $patch->finish("Added bots to queues");
}
Esempio n. 11
0
<?php

defined("_VALID_ACCESS") || die('Direct access forbidden');
// this patch has been renamed to make update process right
// 4bb2048388cd0807ac707edeaa67dfa2 is:
// modules/Utils/RecordBrowser/patches/20140814_add_processing_order.php
$db = new PatchesDB();
if ($db->was_applied('4bb2048388cd0807ac707edeaa67dfa2')) {
    return;
}
$recordsets = Utils_RecordBrowserCommon::list_installed_recordsets();
$checkpoint = Patch::checkpoint('recordset');
$processed = $checkpoint->get('processed', array());
foreach ($recordsets as $tab => $caption) {
    if (isset($processed[$tab])) {
        continue;
    }
    $processed[$tab] = true;
    Patch::require_time(3);
    $tab = $tab . "_field";
    $columns = DB::MetaColumnNames($tab);
    if (!isset($columns['PROCESSING_ORDER'])) {
        PatchUtil::db_add_column($tab, 'processing_order', 'I2');
        DB::Execute("UPDATE {$tab} SET processing_order=position");
    }
    $checkpoint->set('processed', $processed);
}
Esempio n. 12
0
<?php

include "../patches.php";
$patch = new Patch(1);
// Special case, we create it if it doesn't exist, so no error occurs.
$createPatches = "CREATE TABLE IF NOT EXISTS `patches` (\n    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n    `patch_num` INT(11) UNSIGNED NOT NULL,\n    `description` TEXT NOT NULL,\n    PRIMARY KEY (`id`),\n    KEY `patch_num` (`patch_num`)\n    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
db()->execute($createPatches);
if (!$patch->exists()) {
    $patch->finish("Starting the patch system");
}
Esempio n. 13
0
            }
            break;
            /*
             * This is for the first revision of the URI schema.
             * /update2/0/%PRODUCT%/%VERSION%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/update.xml
             */
        /*
         * This is for the first revision of the URI schema.
         * /update2/0/%PRODUCT%/%VERSION%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/update.xml
         */
        case 0:
        default:
            // Instantiate Update object and set updateVersion.
            $update = new Update();
            // Instantiate Patch object and set Path based on passed args.
            $patch = new Patch($productBranchVersions, $nightlyChannels, 'complete');
            $patch->findPatch($clean['product'], $clean['platform'], $clean['locale'], $clean['version'], $clean['build'], null);
            if ($patch->isPatch()) {
                $xml->setPatchLine($patch);
            }
            // If we have a new build, draw the update block and patch line.
            // If there is no valid patch file, client will receive no updates by default.
            if ($xml->hasPatchLine()) {
                $xml->startUpdate($update);
                $xml->drawPatchLines();
                $xml->endUpdate();
            }
            break;
    }
}
// If we are debugging output plaintext and exit.
Esempio n. 14
0
<?php

include "../patches.php";
$patch = new Patch(7);
if (!$patch->exists()) {
    $addWebcamID = "ALTER TABLE bots ADD COLUMN `webcam_image_id` INT(11) UNSIGNED NOT NULL DEFAULT '0'";
    db()->execute($addWebcamID);
    $patch->finish("Adding webcam image to bot temporarily");
}
Esempio n. 15
0
<?php

include "../patches.php";
$patch = new Patch(15);
if (!$patch->exists()) {
    $sql = "ALTER TABLE queues ADD COLUMN `delay` int(11) unsigned NOT NULL DEFAULT 0 AFTER name";
    db()->execute($sql);
    $patch->finish("Added queue delay");
}
Esempio n. 16
0
/**
 * A ChangeSet has patches which has operations
 * this function is used to integrate these operations
 * It's a local changeSet (downloaded from a remote site)
 * @param <String> $changeSetId with NS
 */
function integrate($changeSetId, $patchIdList, $relatedPushServer, $csName)
{
    //global $wgScriptExtension;
    // $patchIdList = getPatchIdList($changeSetId);
    //  $lastPatch = utils::getLastPatchId($pageName);
    global $wgServerName, $wgScriptPath, $wgScriptExtension, $wgOut;
    $urlServer = 'http://' . $wgServerName . $wgScriptPath . "/index.php/{$csName}";
    wfDebugLog('p2p', '@@@@@@@@@@@@@@@@@@@ - function integrate : ' . $changeSetId);
    $i = 1;
    $j = count($patchIdList);
    $pages = array();
    foreach ($patchIdList as $patchId) {
        $name = 'patch';
        $sub = substr($patchId, 6, 3);
        wfDebugLog('p2p', '  -> patchId : ' . $patchId);
        if (!utils::pageExist($patchId)) {
            //if this patch exists already, don't apply it
            wfDebugLog('p2p', '      -> patch unexist');
            $url = utils::lcfirst($relatedPushServer) . "/api.php?action=query&meta=patch&papatchId=" . $patchId . '&format=xml';
            wfDebugLog('p2p', '      -> getPatch request url ' . $url);
            $patch = utils::file_get_contents_curl($url);
            /*test if it is a xml file. If not, the server is not reachable via the url
             * Then we try to reach it with the .php5 extension
             */
            if (strpos($patch, "<?xml version=\"1.0\"?>") === false) {
                $url = utils::lcfirst($relatedPushServer) . "/api.php5?action=query&meta=patch&papatchId=" . $patchId . '&format=xml';
                wfDebugLog('p2p', '      -> getPatch request url ' . $url);
                $patch = utils::file_get_contents_curl($url);
            }
            if (strpos($patch, "<?xml version=\"1.0\"?>") === false) {
                $patch = false;
            }
            //echo $patch;
            if ($patch === false) {
                throw new MWException(__METHOD__ . ': Cannot connect to Push Server (Patch API)');
            }
            $patch = trim($patch);
            wfDebugLog('p2p', '      -> patch content :' . $patch);
            $dom = new DOMDocument();
            $dom->loadXML($patch);
            $patchs = $dom->getElementsByTagName($name);
            //when the patch is not found, mostly when the id passed
            //through the url is wrong
            if (empty($patchs) || is_null($patchs)) {
                throw new MWException(__METHOD__ . ': Error: Patch not found!');
            }
            //        $patchID = null;
            foreach ($patchs as $p) {
                if ($p->hasAttribute("onPage")) {
                    $onPage = $p->getAttribute('onPage');
                }
                if ($p->hasAttribute("previous")) {
                    $previousPatch = $p->getAttribute('previous');
                }
                if ($p->hasAttribute("siteID")) {
                    $siteID = $p->getAttribute('siteID');
                }
                if ($p->hasAttribute("mime")) {
                    $Mime = $p->getAttribute('mime');
                }
                if ($p->hasAttribute("size")) {
                    $Size = $p->getAttribute('size');
                }
                if ($p->hasAttribute("url")) {
                    $Url = $p->getAttribute('url');
                }
                if ($p->hasAttribute("DateAtt")) {
                    $Date = $p->getAttribute('DateAtt');
                }
                if ($p->hasAttribute("siteUrl")) {
                    $SiteUrl = $p->getAttribute('siteUrl');
                }
                if ($p->hasAttribute("causal")) {
                    $causal = $p->getAttribute('causal');
                }
            }
            $operations = null;
            $op = $dom->getElementsByTagName('operation');
            foreach ($op as $o) {
                $operations[] = $o->firstChild->nodeValue;
            }
            $lastPatch = utils::getLastPatchId($onPage);
            if ($lastPatch == false) {
                $lastPatch = 'none';
            }
            //            foreach ($operations as $operation) {
            //                $operation = operationToLogootOp($operation);
            //                if ($operation!=false && is_object($operation)) {
            //                    logootIntegrate($operation, $onPage);
            //                }
            //            }
            if (!in_array($onPage, $pages)) {
                $onPage1 = str_replace(array(' '), array('_'), $onPage);
                utils::writeAndFlush("<span style=\"margin-left:60px;\">Page: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php/{$onPage1}>" . $onPage . "</A></span><br/>");
                $pages[] = $onPage;
            }
            if ($sub === 'ATT') {
                touch(utils::prepareString($Mime, $Size, $Url));
                $DateLastPatch = utils::getLastAttPatchTimestamp($onPage);
                //$DateOtherPatch = utils::getOtherAttPatchTimestamp($patchIdList);
                if ($DateLastPatch == null) {
                    downloadFile($Url);
                    $edit = true;
                    utils::writeAndFlush("<span style=\"margin-left:98px;\">download attachment (" . round($Size / 1000000, 2) . "Mo)</span><br/>");
                } elseif ($DateLastPatch < $Date) {
                    downloadFile($Url);
                    $edit = true;
                    utils::writeAndFlush("<span style=\"margin-left:98px;\">download attachment (" . round($Size / 1000000, 2) . "Mo)</span><br/>");
                } else {
                    newRev($onPage);
                    $edit = false;
                }
                unlink(utils::prepareString($Mime, $Size, $Url));
            }
            utils::writeAndFlush("<span style=\"margin-left:80px;\">" . $i . "/" . $j . ": Integration of Patch: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php/{$patchId}>" . $patchId . "</A></span><br/>");
            if ($sub === 'ATT') {
                $rev = logootIntegrateAtt($onPage, $edit);
                if ($rev > 0) {
                    $lop = array();
                    foreach ($operations as $o) {
                        if ($o instanceof LogootOperation) {
                            $lop[] = $o;
                        } else {
                            $lop[] = operationToLogootOp($o);
                        }
                    }
                    $patch = new Patch(true, true, new LogootPatch($patchId, $lop), $SiteUrl, $causal, $patchId, $lastPatch, $siteID, $Mime, $Size, $Url, $Date);
                    $patch->storePage($onPage, $rev);
                } else {
                    throw new MWException(__METHOD__ . ': article not saved!');
                }
            } else {
                list($rev, $operations) = logootIntegrate($operations, $onPage, $sub);
                if ($rev > 0) {
                    $patch = new Patch(true, false, $operations, $SiteUrl, $causal, $patchId, $lastPatch, $siteID, null, null, null, null);
                    $patch->storePage($onPage, $rev);
                } else {
                    throw new MWException(__METHOD__ . ': article not saved!');
                }
            }
        }
        //end if pageExists
        $i++;
    }
    utils::writeAndFlush("<span style=\"margin-left:30px;\">Go to <A HREF=" . $urlServer . ">ChangeSet</A></span> <br/>");
}
Esempio n. 17
0
 public function runUpdate($XML)
 {
     $IDs = array();
     $XML->lCV3();
     while ($t = $XML->getNextEntry()) {
         $ac = new anyC();
         $ac->setCollectionOf("Patch");
         $ac->addAssocV3("PatchNummer", "=", $t->A("PatchNummer"));
         $P = $ac->getNextEntry();
         if ($P == null) {
             $IDs[] = $t->newMe();
         } else {
             $nP = new Patch($P->getID());
             $AS = $t->getA();
             unset($AS->PatchID);
             $nP->setA($AS);
             $nP->saveMe();
             $IDs[] = $P->getID();
         }
     }
     return $IDs;
 }
Esempio n. 18
0
<?php

include "../patches.php";
$patch = new Patch(6);
if (!$patch->exists()) {
    $createTable = "CREATE TABLE `engine_os` (\n\t\t`engine_id` INT(11) UNSIGNED NOT NULL,\n\t\t`os` ENUM('osx','linux','win','raspberrypi'),\n\t\tPRIMARY KEY (`engine_id`, `os`)\n\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8";
    db()->execute($createTable);
    $patch->finish("Creating Engine OS table");
}
Esempio n. 19
0
<?php

defined("_VALID_ACCESS") || die('Direct access forbidden');
$recordsets = Utils_RecordBrowserCommon::list_installed_recordsets();
$checkpoint = Patch::checkpoint('recordset');
$processed = $checkpoint->get('processed', array());
foreach ($recordsets as $tab => $caption) {
    if (isset($processed[$tab])) {
        continue;
    }
    $processed[$tab] = true;
    Patch::require_time(5);
    $tab = $tab . "_field";
    PatchUtil::db_add_column($tab, 'export', 'I1 DEFAULT 1');
    $checkpoint->set('processed', $processed);
}
Esempio n. 20
0
if (!$files_checkpoint->is_done()) {
    if ($files_checkpoint->has('files')) {
        $files = $files_checkpoint->get('files');
    } else {
        $files = 0;
    }
    if ($files_checkpoint->has('files_qty')) {
        $files_qty = $files_checkpoint->get('files_qty');
    } else {
        $files_qty = DB::GetOne('SELECT count(*) FROM utils_attachment_file');
        $files_checkpoint->set('files_qty', $files_qty);
    }
    while ($ret = DB::SelectLimit('SELECT f.id,f.attach_id as aid,f.original FROM utils_attachment_file f ORDER BY f.id', 1, $files++)) {
        $row = $ret->FetchRow();
        if (!$row) {
            break;
        }
        if (file_exists(DATA_DIR . '/Utils_Attachment/' . $row['aid'] . '/' . $row['id'])) {
            Patch::set_message('Processing file: ' . $files . '/' . $files_qty);
            $files_checkpoint->require_time(2);
            $fsid = Utils_FileStorageCommon::write_file($row['original'], DATA_DIR . '/Utils_Attachment/' . $row['aid'] . '/' . $row['id'], 'attachment_file/' . $row['id']);
            unlink(DATA_DIR . '/Utils_Attachment/' . $row['aid'] . '/' . $row['id']);
            DB::Execute('UPDATE utils_attachment_file SET filestorage_id=%d WHERE id=%d', array($fsid, $row['id']));
        }
        $files_checkpoint->set('files', $files);
    }
    $files_checkpoint->done();
}
DB::Execute('DELETE FROM utils_attachment_download WHERE attach_file_id in (SELECT id FROM utils_attachment_file WHERE filestorage_id=0)');
DB::Execute('DELETE FROM utils_attachment_file WHERE filestorage_id=0');
DB::Execute('ALTER TABLE utils_attachment_file ADD FOREIGN KEY (filestorage_id) REFERENCES utils_filestorage_files(id)');
Esempio n. 21
0
<?php

include "../patches.php";
$patch = new Patch(2);
if (!$patch->exists()) {
    $addRetirementSQL = "ALTER TABLE bots\n  MODIFY COLUMN status\n  ENUM('idle','slicing','working','waiting','error','maintenance','offline','retired')\n  DEFAULT 'idle'";
    db()->execute($addRetirementSQL);
    $patch->finish("Allowing a bot to be retired");
}
Esempio n. 22
0
    if (!$tab_ids_checkpoint->is_done()) {
        Patch::require_time(20);
        if (DB::is_postgresql()) {
            DB::Execute('ALTER TABLE recordbrowser_table_properties DROP CONSTRAINT recordbrowser_table_properties_pkey');
            DB::Execute('ALTER TABLE recordbrowser_table_properties ADD COLUMN id SERIAL PRIMARY KEY');
        } else {
            DB::Execute('ALTER TABLE recordbrowser_table_properties DROP PRIMARY KEY');
            DB::Execute('ALTER TABLE recordbrowser_table_properties ADD id SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY');
        }
        DB::CreateIndex('recordbrowser_table_properties_tab', 'recordbrowser_table_properties', 'tab', array('UNIQUE' => 1));
        $tab_ids_checkpoint->done();
    }
}
$field_ids_checkpoint = Patch::checkpoint('field_ids');
if (!$field_ids_checkpoint->is_done()) {
    Patch::require_time(20);
    $recordsets = Utils_RecordBrowserCommon::list_installed_recordsets();
    foreach ($recordsets as $tab => $caption) {
        $tab_f = $tab . "_field";
        $columns = DB::MetaColumnNames($tab_f);
        if (!isset($columns['ID'])) {
            if (DB::is_postgresql()) {
                @DB::Execute('ALTER TABLE ' . $tab_f . ' DROP CONSTRAINT ' . $tab_f . '_pkey');
                DB::Execute('ALTER TABLE ' . $tab_f . ' ADD COLUMN id SERIAL PRIMARY KEY');
            } else {
                @DB::Execute('ALTER TABLE ' . $tab_f . ' DROP PRIMARY KEY');
                DB::Execute('ALTER TABLE ' . $tab_f . ' ADD id SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY');
            }
            DB::CreateIndex($tab_f . '_field', $tab_f, 'field', array('UNIQUE' => 1));
        }
    }
Esempio n. 23
0
<?php

include "../patches.php";
$patch = new Patch(21);
if (!$patch->exists()) {
    // Create new type column
    $sql = "ALTER TABLE oauth_token ADD COLUMN `type2` enum('request', 'verified', 'access') AFTER type";
    db()->execute($sql);
    // Kill tokens that are stuck in a bad state due to a previous issue
    $sql = "DELETE from oauth_token where type=2 AND verified=0";
    // Migrate the 3 types over
    $sql = "UPDATE oauth_token SET type2='request' WHERE type=1 AND verified=0";
    db()->execute($sql);
    $sql = "UPDATE oauth_token SET type2='verified' WHERE type=1 AND verified=1";
    db()->execute($sql);
    $sql = "UPDATE oauth_token SET type2='access' WHERE type=2 AND verified=1";
    db()->execute($sql);
    $sql = "ALTER TABLE oauth_token DROP COLUMN type";
    db()->execute($sql);
    $sql = "ALTER TABLE oauth_token DROP COLUMN verified";
    db()->execute($sql);
    $sql = "ALTER TABLE oauth_token CHANGE type2 type enum('request', 'verified', 'access')";
    db()->execute($sql);
    $patch->finish("Converting oauth token codes");
}
Esempio n. 24
0
<?php

include "../patches.php";
$patch = new Patch(19);
if (!$patch->exists()) {
    $createSql = "CREATE TABLE IF NOT EXISTS `notifications` (\n\t\t\t  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `timestamp` datetime NOT NULL,\n\t\t\t  `from_user_id` int(11) unsigned NULL,\n\t\t\t  `to_user_id` int(11) unsigned NULL,\n\t\t\t  `title` varchar(255) NOT NULL,\n\t\t\t  `content` text NOT NULL,\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  FOREIGN KEY (`from_user_id`) REFERENCES users(`id`) ON DELETE CASCADE,\n\t\t\t  FOREIGN KEY (`to_user_id`) REFERENCES users(`id`) ON DELETE CASCADE\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
    db()->execute($createSql);
    $sql = "ALTER TABLE users ADD COLUMN `last_notification` int(11) NOT NULL DEFAULT 0 AFTER `registered_on`";
    db()->execute($sql);
    $content = "Welcome to the new notification center! I'm going to use this to let you know ";
    $content .= "about awesome new updates that are happening to BotQueue. Eventually, you will ";
    $content .= "receive updates to comments and messages from other users through this system. ";
    $content .= "I'm still working on the placement of the notification icon in the full screen ";
    $content .= "mode, because I want the icon to be to the left of the username.";
    $content .= "\n\n";
    $content .= "If you have any issues, or even suggestions, please let me know in either the ";
    $content .= "<a href=\"https://groups.google.com/forum/#!forum/botqueue\">google group</a> or at ";
    $content .= "<a href=\"https://github.com/Hoektronics/BotQueue/issues\">GitHub issues</a>.";
    $content .= "\n\n";
    $content .= "Thank you for using BotQueue!";
    $content .= "\n\n";
    $content .= " ~ Justin Nesselrotte";
    $notification = new Notification();
    $notification->set('from_user_id', null);
    // From the system
    $notification->set('to_user_id', null);
    // To everyone
    $notification->set('timestamp', date("2014-12-24 00:00:00"));
    $notification->set('title', 'New notification system');
    $notification->set('content', $content);
    $notification->save();
Esempio n. 25
0
<?php

include "../patches.php";
$patch = new Patch(25);
if (!$patch->exists()) {
    $sql = "ALTER table bots ADD KEY `name` (`name`)";
    db()->execute($sql);
    $patch->finish("Adding MySQL keys");
}
Esempio n. 26
0
<?php

include "../patches.php";
$patch = new Patch(4);
if (!$patch->exists()) {
    $addPausedSQL = "ALTER TABLE bots\n  MODIFY COLUMN status\n  ENUM('idle','slicing','working','paused','waiting','error','maintenance','offline','retired') DEFAULT 'idle'";
    db()->execute($addPausedSQL);
    $patch->finish("Allowing a bot to be paused");
}
Esempio n. 27
0
 /**
  * Init checkpoints data file.
  *
  * We'd like to store them separately, because in some scenarios patches
  * may be run simultanously. E.g.
  * 1. Run patch B without success - checkpoint file is left
  * 2. Create patch A (before B)
  * 3. Running patch A could overwrite B's checkpoints.
  * That's the reason why patch id is in the filename
  */
 private function init_checkpoints()
 {
     $dir = rtrim(DATA_DIR, '/\\') . '/patch_' . $this->get_identifier();
     self::$checkpoints_dir = $dir;
     if (file_exists($dir)) {
         if (!is_dir($dir)) {
             throw new ErrorException('Cannot create patch checkpoints dir');
         }
     } else {
         mkdir($dir);
     }
 }
Esempio n. 28
0
            $patchParser->parse($patch_xml);
            $patch_array = $patchParser->getParsedArray();
            if ($_POST["ignore_version"]) {
                $patch_array["applied_version"] = VERSION;
            }
            if ($_POST["install_upload"]) {
                $current_patch_list = array('atutor_patch_id' => $patch_array['atutor_patch_id'], 'applied_version' => $patch_array['applied_version'], 'patch_folder' => $patchURL, 'available_to' => 'private', 'author' => $patch_array['author'], 'sql' => $patch_array['sql'], 'description' => $patch_array['description'], 'dependent_patches' => $patch_array['dependent_patches']);
            }
            if ($_POST["install"]) {
                $current_patch_list = $patch_list_array[$id];
                $current_patch_list["sql"] = $patch_array["sql"];
            }
            if ($_POST["install_upload"] && is_patch_installed($patch_array["atutor_patch_id"])) {
                $msg->addError('PATCH_ALREADY_INSTALLED');
            } else {
                $patch = new Patch($patch_array, $current_patch_list, $skipFilesModified, $patchURL);
                if ($patch->applyPatch()) {
                    $patch_id = $patch->getPatchID();
                }
            }
        }
    }
}
// end of patch installation
// display permission and backup files message
if (isset($_REQUEST['patch_id'])) {
    $patch_id = $_REQUEST['patch_id'];
} elseif ($_POST['patch_id']) {
    $patch_id = $_POST['patch_id'];
}
if ($patch_id > 0) {
Esempio n. 29
0
<?php

include "../patches.php";
$patch = new Patch(3);
if (!$patch->exists()) {
    $addCanceledSQL = "ALTER TABLE jobs\n  MODIFY COLUMN status\n  ENUM('available','taken','slicing','downloading','qa','complete','failure','canceled') NOT NULL DEFAULT 'available'";
    db()->execute($addCanceledSQL);
    $patch->finish("Allowing a job to be canceled");
}
 /**
  * Constructor - pass it {@see exec()} $output
  *
  * @param array $output
  */
 public function __construct($command, $output, Patch $patch, $dryRun = FALSE)
 {
     $output = 'Patch ' . $patch->getChecksum() . ' ' . ($dryRun ? 'would fail' : 'failed') . "!\n" . 'Error executing command "' . $command . '":' . "\n" . (is_array($output) ? implode("\n", $output) : $output);
     parent::__construct($output);
 }