notice (sprintf ('Applying patch %s', $this->getId ())); if ($this->checkPreconditions ()) { $this->applyBody (); if ($this->hasPostconditionScript ()) { include_once $this->getPostconditionScript(); } } } function validate () { if ($this->hasPreconditionScript ()) { if (! $this->validatePhpScript ($this->getPreconditionScript ())) { return false; } } if ($this->hasPostconditionScript ()) { if (! $this->validatePhpScript ($this->getPostconditionScript ())) { return false; } } return true; } abstract protected function applyBody (); abstract function getId (); function __call ($method, $arguments) { $logger = $this->logger (); $logger_function = array ('emerg', 'alert', 'crit', 'err', 'warn', 'notice', 'info', 'debug'); if (in_array ($method, $logger_function)) { if (isset ($logger)) { return call_user_func_array (array ($logger, $method), $arguments); } } else { throw new Exception ("Invalid access to method `$method`."); } } function logger (Zend_Log $logger=null) { if (isset ($logger)) { $this->logger = $logger; } else { return $this->logger; } } function checkPreconditions () { if ($this->hasPreconditionScript ()) { $result = require $this->getPreconditionScript (); return $result; } return true; } function setPreconditionScript ($precondition_script) { $this->precondition_script = $precondition_script; } function getPreconditionScript () { return $this->precondition_script; } function hasPreconditionScript () { return isset ($this->precondition_script); } function setPostconditionScript ($postcondition_script) { $this->postcondition_script = $postcondition_script; } function getPostconditionScript () { return $this->postcondition_script; } function hasPostconditionScript () { return isset ($this->postcondition_script); } private function validatePhpScript ($filename) { $command = sprintf ('php --syntax-check %s > /dev/null 2>&1', escapeshellcmd ($filename)); $exit_code = 0; system ($command, $exit_code); return $exit_code == 0; } }