private function handleUpdate($requestData)
 {
     if ($this->authenticator->userAuthenticates($requestData["email"], $requestData["auth-key"])) {
         $versioning = new DIM_Versioning();
         if ($versioning->databaseNeedsUpdating()) {
             $querymanager = new DIM_QueryManager();
             $querymanager->beginUpdate();
             return "1:update-success";
         }
         return "0:no-update-available";
     }
     return "0:unauthed";
 }
 private function __indexPage()
 {
     $versioning = new DIM_Versioning();
     $link = new XMLElement('link');
     $this->addElementToHead($link, 500);
     $this->setPageType('table');
     $this->appendSubheading(__('Database Updating'));
     $fieldSet = new XMLElement('fieldset', '', array('class' => 'settings'));
     $fieldSet->appendChild(new XMLElement('legend', 'Database Update'));
     $message = new XMLElement('div');
     if ($versioning->databaseNeedsUpdating()) {
         $querymanager = new DIM_QueryManager();
         $querymanager->beginUpdate();
         $message->appendChild(new XMLElement('h2', "Update Completed!"));
         redirect('../?message=update-success');
     } else {
         $message->appendChild(new XMLElement('h2', "Database Already Up To Date"));
     }
     $fieldSet->appendChild($message);
     $this->Form->appendChild($fieldSet);
 }
 public function requestCheckin(&$error, $newVersion, $commitMessage)
 {
     $config = $this->getConfiguration();
     $versioning = new DIM_Versioning();
     $requestData = array("action" => "checkin", "email" => $config["client"]["user-email"], "auth-key" => $config["client"]["auth-key"], "version" => $newVersion, "old-version" => $versioning->getLatestVersion(), "commit-message" => $commitMessage);
     $rawResponse = Network_IO::makeServerRequest($config["client"]["server-host"], $requestData);
     $responseParts = explode(":", $rawResponse);
     if ($responseParts[0] == "1") {
         // successful checkin!
         $this->state->checkIn();
         $this->logger->addLogItem("Database Checked In", "state");
         $queryManager = new DIM_QueryManager();
         $versionFileName = $queryManager->makeVersionFile($responseParts[1], $responseParts[2]);
         $this->logger->addLogItem("Version file {$versionFileName} created", "version");
         $newVersion = $versioning->addNewVersion($responseParts[1], $responseParts[2]);
         $this->logger->addLogItem("Database now at version {$newVersion}", "version");
         return true;
     } else {
         $error = $responseParts[1];
         return false;
     }
 }
 public function resumeUpdate()
 {
     // creates $updateCache
     include $this->getUpdateCacheFilename();
     // sort it backwards so we can POP (which is a nicer sound than SHIFT)
     krsort($updateCache);
     $versioning = new DIM_Versioning();
     $database = new Database_IO($this->getDatabaseSettings());
     while ($update = array_pop($updateCache)) {
         $database->query(base64_decode($update["queries"]), MULTI_QUERY, true);
         $versioning->addNewVersion($update["version"], $update["commitMessage"]);
         $this->logger->addLogItem("Local database now updated to version " . $update["version"], "update");
         // save the update cache now in case we die on the next iteration
         $this->saveUpdateCache($updateCache);
     }
     // if we get to here then all is well!
     unlink($this->getUpdateCacheFilename());
 }
 public function appendAlerts($context)
 {
     $this->createFolders();
     //just to be on the safe side
     $this->checkWritableDirectories();
     if (!$this->config->isExtensionConfigured()) {
         Administration::instance()->Page->pageAlert(__('Database Integration Manager is installed but not configured. <a href=\'' . SYMPHONY_URL . '/extension/database_integration_manager\'>Configure it now</a>.'), Alert::ERROR);
     } else {
         $versioning = new DIM_Versioning();
         if ($versioning->databaseNeedsUpdating()) {
             Administration::instance()->Page->pageAlert(__("<a href='" . SYMPHONY_URL . "/extension/database_integration_manager/update'> Your Database Is Out Of Date Update It</a>."), Alert::ERROR);
         }
     }
 }
 private function __indexPage()
 {
     $versioning = new DIM_Versioning();
     $link = new XMLElement('link');
     $this->addElementToHead($link, 500);
     $this->setPageType('form');
     $this->appendSubheading(__('Database Check In'));
     $checkinFieldset = new XMLElement('fieldset');
     $checkinFieldset->setAttribute("class", "settings picker");
     $checkinFieldset->appendChild(new XMLElement('legend', __("Version Information")));
     if (isset($_POST['success'])) {
         $successWrapper = new XMLElement('div', '', array('class' => 'two columns'));
         $successWrapper->appendChild(new XMLElement('div', new XMLElement("h3", "Database Checked in"), array('class' => 'column')));
         $successWrapper->appendChild(new XMLElement('div', new XMLElement('div', '<a class="button" href="../">Return to Configuration</a>'), array('class' => 'column')));
         $checkinFieldset->appendChild($successWrapper);
         $this->Form->appendChild($checkinFieldset);
     } else {
         //pre fill information
         $versionData = $versioning->getLatestVersion() + 1;
         if (isset($_POST['checkin']['version'])) {
             $versionData = $_POST['checkin']['version'];
         }
         $versionLabel = Widget::Label("Version");
         $versionLabel->appendChild(Widget::Input("checkin[version]", strval($versionData)));
         $messageLabel = Widget::Label("Commit Message");
         $messageLabel->appendChild(Widget::Input("checkin[message]", $_POST['checkin']['message']));
         //if errors
         if (isset($_POST['error']['version'])) {
             $versionLabel->setAttribute('class', 'invalid');
             $versionError = "Please enter a version number (Current Version = " . $versioning->getLatestVersion() . ')';
             switch ($_POST['error']['version']) {
                 case 'invalid':
                     $versionError = 'Invalid Version Number, must be a number (Current Version = ' . $versioning->getLatestVersion() . ')';
                     break;
                 case 'less-than-version':
                     $versionError = 'Version already exists or is less than current version( Current Version = ' . $versioning->getLatestVersion() . ')';
                     break;
             }
             $versionLabel->appendChild(new XMLElement('p', $versionError));
         }
         if (isset($_POST['error']['message'])) {
             $messageLabel->setAttribute('class', 'invalid');
             $messageLabel->appendChild(new XMLElement('p', 'Please enter a commit message'));
         }
         $columnWrapper = new XMLElement('div', '', array('class' => 'two columns'));
         $columnWrapper->appendChild(new XMLElement('div', $versionLabel, array('class' => 'column', "readonly" => 'readonly')));
         $columnWrapper->appendChild(new XMLElement('div', $messageLabel, array('class' => 'column')));
         $checkinFieldset->appendChild($columnWrapper);
         $this->Form->appendChild($checkinFieldset);
         $saveDiv = new XMLElement('div');
         $saveDiv->setAttribute('class', 'actions');
         $saveDiv->appendChild(Widget::Input('action[checkin]', __('Check-In!'), 'submit', array('accesskey' => 's')));
         $this->Form->appendChild($saveDiv);
     }
 }