/** * Display agreement screen to ensure start sample * data installation process * * @return void */ public function confirmAction() { // Make sure current template is not out-of-date $update = new JSNTplWidgetUpdate(); $update->checkUpdateAction(); $update = $update->getResponse(); // Render confirm view $this->render('confirm', array('template' => $this->template, 'update' => $update)); }
/** * Check if there is new update for installed JoomlaShine product. * * @return void */ protected static function checkUpdate() { // Check for update every predefined period of time if (time() - (int) self::$_tplfwParams->get('update-check', 0) < JSN_TPLFRAMEWORK_CHECK_UPDATE_PERIOD) { return; } // Backup request variable $backup = JFactory::getApplication()->input->getCmd('template'); // Get method to execute database query $db = JFactory::getDbo(); $executeMethod = method_exists($db, 'query') ? 'query' : 'execute'; // Get list of installed JoomlaShine template $q = $db->getQuery(true); $q->select('extension_id, name, type, element'); $q->from('#__extensions'); $q->where('type = ' . $q->quote('template')); $q->where('(custom_data = "jsntemplate" OR manifest_cache LIKE \'%,"group":"jsntemplate"}\')'); $db->setQuery($q); if ($templates = $db->loadObjectList()) { foreach ($templates as $template) { // Set template name to request variable JFactory::getApplication()->input->set('template', $template->element); // Trigger check-update action of the update widget $widget = new JSNTplWidgetUpdate(); $widget->checkUpdateAction(); // Get result $result = $widget->getResponse(); // Do we have update? foreach (array('template', 'framework') as $ext) { if ($result[$ext]['hasUpdate']) { // Get extension details for template framework if ($ext == 'framework' and !isset($framework)) { $q = $db->getQuery(true); $q->select('extension_id, name, type, element'); $q->from('#__extensions'); $q->where('type = ' . $q->quote('plugin')); $q->where('folder = ' . $q->quote('system')); $q->where('element = ' . $q->quote(basename(JSN_PATH_TPLFRAMEWORK))); $db->setQuery($q); $framework = $db->loadObject(); } // Generate extension details $ext_id = $ext == 'template' ? (int) $template->extension_id : (int) $framework->extension_id; $name = $ext == 'template' ? $template->name : $framework->name; $type = $ext == 'template' ? $template->type : $framework->type; $elm = $ext == 'template' ? $template->element : $framework->element; // Check if update is stored before if ($ext == 'template' or !isset($current['framework'])) { $q = $db->getQuery(true); $q->select('version'); $q->from('#__updates'); $q->where('extension_id = ' . $ext_id); $db->setQuery($q); $current[$ext] = $db->loadResult(); } // Store update info to Joomla updates table $q = $db->getQuery(true); if ($current[$ext]) { if (version_compare($current[$ext], $result[$ext]['newVersion'], '<')) { $q->update('#__updates'); $q->set('version = ' . $q->quote($result[$ext]['newVersion'])); $q->where('extension_id = ' . $ext_id); $q->where('version = ' . $q->quote($current[$ext])); $db->setQuery($q); $db->{$executeMethod}(); } } else { $q->insert('#__updates'); $q->columns('extension_id, name, element, type, version'); $q->values($ext_id . ', ' . $q->quote(JText::_($name)) . ', ' . $q->quote($elm) . ', ' . $q->quote($type) . ', ' . $q->quote($result[$ext]['newVersion'])); $db->setQuery($q); $db->{$executeMethod}(); } } } } } // Reset update checking status $q = $db->getQuery(true); $q->update('#__extensions'); $q->set("params = '" . json_encode(array('update-check' => time())) . "'"); $q->where('type = ' . $q->quote('plugin')); $q->where('folder = ' . $q->quote('system')); $q->where('element = ' . $q->quote(basename(JSN_PATH_TPLFRAMEWORK))); $db->setQuery($q); $db->{$executeMethod}(); // Restore request variable JFactory::getApplication()->input->set('template', $backup); }