/**
  * Process condition and do action
  * @param Handler $handler Handler ORM
  * @param Audit $audit Audit ORM
  * @return boolean Return TRUE if successful, FALSE otherwise
  */
 public function process(Audit $audit)
 {
     $ret = true;
     $update = new UpdateFile();
     $updateIterator = $update->getIteratorByQueue();
     foreach ($updateIterator as $updateFile) {
         $updateFile->queue = 0;
         $alterTable = new AlterTable();
         $ret = $alterTable->generateSqlChanges($updateFile->getUploadFilename());
         if ($ret === true) {
             $alterTable->executeSqlChanges();
             //$updateFile->active = 0;
             $updateFile->status = 'Completed';
             $updateFile->persist();
         } else {
             $updateFile->status = 'Error: ' . $ret;
             $updateFile->persist();
         }
     }
     return $ret;
 }
示例#2
0
 public function install()
 {
     $filename = $this->getUploadFilename();
     if (file_exists($filename)) {
         $size = sprintf("%u", filesize($filename));
         $units = array('B', 'KB', 'MB', 'GB', 'TB');
         $pow = floor(($size ? log($size) : 0) / log(1024));
         $pow = min($pow, count($units) - 1);
         $size /= pow(1024, $pow);
         if ($pow == 2 && round($size, 1) > 10 || $pow > 2) {
             // queue if > 10 MB
             $this->queue = 1;
             $this->status = 'Pending';
             $this->persist();
         }
     }
     $audit = new Audit();
     $audit->objectClass = 'UpdateManager';
     $audit->userId = (int) Zend_Auth::getInstance()->getIdentity()->personId;
     $audit->message = 'License of update file ' . $this->name . ' from ' . $this->channel . ' channel was accepted';
     $audit->dateTime = date('Y-m-d H:i:s');
     if ($this->queue) {
         $audit->message .= ' and updates pending to apply.';
         $ret = true;
     } else {
         $this->queue = 0;
         $alterTable = new AlterTable();
         $ret = $alterTable->generateSqlChanges($filename);
         if ($ret === true) {
             $alterTable->executeSqlChanges();
             //$this->active = 0;
             $this->status = 'Completed';
             $this->persist();
             $audit->message .= ' and updates applied successfully.';
         } else {
             $audit->message .= ' and updates failed to apply.';
             $this->status = 'Error: ' . $ret;
             $this->persist();
         }
     }
     $audit->persist();
 }
 public function viewDetailsAction()
 {
     $updateFileId = (int) $this->_getParam('updateFileId');
     $updateFile = new UpdateFile();
     $updateFile->updateFileId = $updateFileId;
     $updateFile->populate();
     $alterTable = new AlterTable();
     $this->view->name = $updateFile->channel . ': ' . $updateFile->name;
     $this->view->data = $alterTable->generateChanges($updateFile->getUploadFilename());
     $this->render('view-details');
 }
示例#4
0
 /**
  * Adds keys to an alter table query
  *
  * @param AlterTable $alter The alert table query
  * @param array $keys The table keys to add
  */
 private function addKeys($alter, $keys)
 {
     // Get the fields out of the alter query
     $fields = $alter->Fields();
     // Add keys if any of the fields have associated keys
     for ($i = 0; $i < count($fields); $i++) {
         // Grab the name of the field
         $name = $fields[$i]->Name();
         // Make the column primary if the key is a primary key AND the associated name matches
         if (array_key_exists("primary", $keys) && $keys["primary"] == $name) {
             $alter->AddKey("primary", $keys["primary"]);
         }
         // If there are any unique keys
         if (array_key_exists("unique", $keys)) {
             // Add the unique keys as needed
             for ($j = 0; $j < count($keys["unique"]); $j++) {
                 // If the name of the unique key matches, add the key
                 if ($keys["unique"][$j] == $name) {
                     $alter->AddKey("unique", $keys["unique"][$j]);
                 }
             }
         }
         // If the column needs to be set to auto-increment
         if (array_key_exists("ai", $keys) && $keys["ai"] == $name) {
             $alter->SetAutoIncrement($keys["ai"]);
         }
     }
 }