/**
  * 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;
 }
Esempio n. 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 processApplyAction()
 {
     $updateFileId = (int) $this->_getParam('updateFileId');
     $updateFile = new UpdateFile();
     $updateFile->updateFileId = $updateFileId;
     $updateFile->populate();
     $data = $updateFile->data;
     $alterTable = new AlterTable();
     $ret = $alterTable->generateSqlChanges($data);
     if ($ret === true) {
         $alterTable->executeSqlChanges();
         $updateFile->active = 0;
         $updateFile->persist();
         $audit = new Audit();
         $audit->objectClass = 'UpdateManager';
         $audit->userId = (int) Zend_Auth::getInstance()->getIdentity()->personId;
         $audit->message = 'License of update file ' . $updateFile->name . ' from ' . $updateFile->channel . ' channel was accepted and updates applied successfully.';
         $audit->dateTime = date('Y-m-d H:i:s');
         $audit->persist();
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($ret);
 }