/** * Retrieves the update data from our home server * * @param bool $overrideCache * * @return array */ public function fetchData($overrideCache = false) { $cacheFile = $this->factory->getSystemPath('cache') . '/lastUpdateCheck.txt'; // Check if we have a cache file and try to return cached data if so if (!$overrideCache && is_readable($cacheFile)) { $update = (array) json_decode(file_get_contents($cacheFile)); // Check if the user has changed the update channel, if so the cache is invalidated if ($update['stability'] == $this->factory->getParameter('update_stability')) { // If we're within the cache time, return the cached data if ($update['checkedTime'] > strtotime('-3 hours')) { return $update; } } } // Before processing the update data, send up our metrics try { // Generate a unique instance ID for the site $instanceId = hash('sha1', $this->factory->getParameter('secret_key') . 'Mautic' . $this->factory->getParameter('db_driver')); $data = array('application' => 'Mautic', 'version' => $this->factory->getVersion(), 'phpVersion' => PHP_VERSION, 'dbDriver' => $this->factory->getParameter('db_driver'), 'serverOs' => php_uname('s') . ' ' . php_uname('r'), 'instanceId' => $instanceId, 'installSource' => $this->factory->getParameter('install_source', 'Mautic')); $this->connector->post('https://updates.mautic.org/stats/send', $data, array(), 10); } catch (\Exception $exception) { // Not so concerned about failures here, move along } // Get the update data try { $appData = array('appVersion' => $this->factory->getVersion(), 'phpVersion' => PHP_VERSION, 'stability' => $this->factory->getParameter('update_stability')); $data = $this->connector->post('https://updates.mautic.org/index.php?option=com_mauticdownload&task=checkUpdates', $appData, array(), 10); $update = json_decode($data->body); } catch (\Exception $exception) { // Log the error $logger = $this->factory->getLogger(); $logger->addError('An error occurred while attempting to fetch updates: ' . $exception->getMessage()); return array('error' => true, 'message' => 'mautic.core.updater.error.fetching.updates'); } if ($data->code != 200) { // Log the error $logger = $this->factory->getLogger(); $logger->addError(sprintf('An unexpected %1$s code was returned while attempting to fetch updates. The message received was: %2$s', $data->code, is_string($data->body) ? $data->body : implode('; ', $data->body))); return array('error' => true, 'message' => 'mautic.core.updater.error.fetching.updates'); } // If the user's up-to-date, go no further if ($update->latest_version) { return array('error' => false, 'message' => 'mautic.core.updater.running.latest.version'); } // Last sanity check, if the $update->version is older than our current version if (version_compare($this->factory->getVersion(), $update->version, 'ge')) { return array('error' => false, 'message' => 'mautic.core.updater.running.latest.version'); } // The user is able to update to the latest version, cache the data first $data = array('error' => false, 'message' => 'mautic.core.updater.update.available', 'version' => $update->version, 'announcement' => $update->announcement, 'package' => $update->package, 'checkedTime' => time(), 'stability' => $this->factory->getParameter('update_stability')); file_put_contents($cacheFile, json_encode($data)); return $data; }
/** * @param MauticFactory $factory * * @return void */ public function setFactory(MauticFactory $factory) { $this->factory = $factory; $this->version = $factory->getVersion(); }
/** * @param MauticFactory $factory */ public function __construct(MauticFactory $factory) { $this->factory = $factory; $this->version = $this->factory->getVersion(); }
/** * @param MauticFactory $factory */ public function __construct(MauticFactory $factory) { $this->dateHelper = $factory->getHelper('template.date'); $this->version = $factory->getVersion(); }
/** * @param MauticFactory $factory */ public function __construct(MauticFactory $factory) { $this->factory = $factory; $this->version = substr(hash('sha1', $this->factory->getParameter('secret_key') . $this->factory->getVersion()), 0, 8); }