name = $name; $this->status = $status; } /** * Defines the state * * @param int $status One of the constants of this class */ public function setStatus($status) { if (! in_array($status, [self::NOT_APPLIED, self::ALREADY_APPLIED, self::NEWLY_APPLIED])) { throw new DomainException(); } $this->status = $status; } /** * Get the patches matching the specified statuses * * @param int[] $statuses Allowed statuses * @param bool true to obtain optional patches, false for required only * * @return Patch[] Matching patches */ public static function getPatches($statuses, $optional = false) { $matches = []; foreach (self::$list as $name => $patch) { if (in_array($patch->status, $statuses) && ($optional || ! $patch->optional)) { $matches[$name] = $patch; } } return $matches; } /** * Indicates if the patch is applied * * @return bool true is the patch is applied, false otherwise */ public function isApplied() { return $this->status != self::NOT_APPLIED; } /** * Mark as installed */ public function record() { Installer::getInstance()->query("INSERT INTO tiki_schema (patch_name, install_date) VALUES(?, NOW())", [$this->name]); $this->pushPatchNameToBrowser('build_patch', $this->name); self::$list[$this->name]->setStatus(self::NEWLY_APPLIED); } public function pushPatchNameToBrowser($targetElement, $content) { $scripts = << var element = parent.document.getElementById("{$targetElement}"); if (element) { element.innerHTML = "{$content}"; } HTML; $working_env = php_sapi_name(); if ($working_env != 'cli') { echo $scripts; ob_flush(); } } }