Esempio n. 1
0
 function apply()
 {
     if (!file_exists($this->file)) {
         return false;
     }
     if ($this->apply_status == self::STATUS_OLD) {
         return false;
     }
     self::$current_patch = $this;
     $this->init_checkpoints();
     set_error_handler(array('Patch', 'error_handler'));
     ob_start(array($this, 'output_bufferring_interrupted'));
     try {
         PatchUtil::require_time(1);
         include $this->file;
         $this->apply_status = self::STATUS_SUCCESS;
     } catch (NotEnoughExecutionTimeException $ex) {
         $this->apply_status = self::STATUS_TIMEOUT;
     } catch (PatchException $e) {
         $this->apply_status = self::STATUS_ERROR;
         $this->apply_error = $e->getMessage();
     } catch (Exception $e) {
         $this->apply_status = self::STATUS_ERROR;
         $this->apply_error = "Exception occured.\nFile: {$e->getFile()}\nLine: {$e->getLine()}\nMessage: {$e->getMessage()}";
     }
     $output = ob_get_clean();
     restore_error_handler();
     $this->apply_log = "[{$this->get_file()}] [{$this->get_identifier()}] {$this->apply_status}\n";
     if ($output) {
         $this->apply_log .= " === OUTPUT ===\n{$output}\n === END OUTPUT ===\n";
     }
     if ($this->apply_error) {
         $this->apply_log .= " !!! ERROR !!!\n{$this->apply_error}\n !!! END ERROR !!!\n";
     }
     $return = false;
     if ($this->apply_status == self::STATUS_SUCCESS) {
         $this->mark_applied();
         $this->destroy_checkpoints();
         $return = true;
     }
     self::$current_patch = null;
     return $return;
 }