Example #1
0
 /**
  * Gets a single instance of the class
  *
  * @param   string  $component  - the component name
  *
  * @return CompojoomUtilsComponent|null
  */
 public static function getInstance($component)
 {
     if (!self::$instance) {
         self::$instance = new CompojoomUtilsComponent($component);
     }
     return self::$instance;
 }
Example #2
0
 /**
  * Retrieves the update information of the component, returning an array with the following keys:
  *
  * hasUpdate	True if an update is available
  * version		The version of the available update
  * infoURL		The URL to the download page of the update
  *
  * @param   bool  $force  Set to true if you want to forcibly reload the update information
  *
  * @return  array  See the method description for more information
  */
 public function getUpdates($force = false)
 {
     $db = $this->getDbo();
     // Default response (no update)
     $updateResponse = array('hasUpdate' => false, 'version' => '', 'infoURL' => '');
     if (empty($this->extension_id)) {
         return $updateResponse;
     }
     // If we are forcing the reload, set the last_check_timestamp to 0
     // and remove cached component update info in order to force a reload
     if ($force) {
         // Find the update site IDs
         $updateSiteIds = $this->getUpdateSiteIds();
         if (empty($updateSiteIds)) {
             return $updateResponse;
         }
         // Set the last_check_timestamp to 0
         $query = $db->getQuery(true)->update($db->qn('#__update_sites'))->set($db->qn('last_check_timestamp') . ' = ' . $db->q('0'))->where($db->qn('update_site_id') . ' IN (' . implode(', ', $updateSiteIds) . ')');
         $db->setQuery($query);
         $db->execute();
         // Remove cached component update info from #__updates
         $query = $db->getQuery(true)->delete($db->qn('#__updates'))->where($db->qn('update_site_id') . ' IN (' . implode(', ', $updateSiteIds) . ')');
         $db->setQuery($query);
         $db->execute();
     }
     // Use the update cache timeout specified in com_installer
     $comInstallerParams = CompojoomUtilsComponent::getInstance('com_installer');
     $timeout = 3600 * $comInstallerParams->get('cachetimeout', '6');
     // Load any updates from the network into the #__updates table
     $this->updater->findUpdates($this->extension_id, $timeout);
     // Get the update record from the database
     $query = $db->getQuery(true)->select('*')->from($db->qn('#__updates'))->where($db->qn('extension_id') . ' = ' . $db->q($this->extension_id));
     $db->setQuery($query);
     $updateRecord = $db->loadObject();
     // If we have an update record in the database return the information found there
     if (is_object($updateRecord)) {
         $updateResponse = array('hasUpdate' => true, 'version' => $updateRecord->version, 'infoURL' => $updateRecord->infourl);
     }
     return $updateResponse;
 }