/** * Builds list of available updates to display in the template. * * @return array List of updates data. Each item of the list is associative * array with the following keys: * - "title": string, title of the update. * - "version": string, the latest available version. * - "url": string, URL of the page the updated version can be downloaded * from. * - "description": string, description of the update. */ protected function getAvailableUpdates() { $updates = AvailableUpdate::all(); if (!$updates) { return array(); } $data = array(); foreach ($updates as $update) { $title = $update->target == 'core' ? 'Mibew' : getlocal('{0} plugin', array($update->target)); $data[] = array('title' => $title, 'version' => $update->version, 'url' => $update->url, 'description' => $update->description); } return $data; }
/** * Saves record about available update in the database. * * @param string $target Update's target. Can be either "core" or fully * qualified plugin's name. * @param string $version The latest version at the updates server. * @param string $url URL of the page where the update can be downloaded. * @param string $description Arbitrary update's description. * @return boolean False on failure and true otherwise. To get more info * about the error call {@link UpdateChecker::getErrors()} method. */ protected function saveUpdate($target, $version, $url, $description = '') { try { $update = AvailableUpdate::loadByTarget($target); if (!$update) { // There is no such update in the database. Create a new one. $update = new AvailableUpdate(); $update->target = $target; } $update->version = $version; $update->url = $url; $update->description = $description; $update->save(); } catch (\Exception $e) { $this->errors[] = 'Cannot save available update: ' + $e->getMessage(); return false; } return true; }