| Current Path : /home/purehotels/www/administrator/modules/mod_blz_k2_admin_menu/ |
| Current File : /home/purehotels/www/administrator/modules/mod_blz_k2_admin_menu/install.script.php |
<?php
/**
* @package Blazing K2 Menu for Joomla! 2.5 & Joomla! 3.x
* @version 1.0: install.script.php August, 2016
* @author Dario Pintarić
* @copyright (C) 2016 - dblaze.eu
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*
*/
// No direct access.
defined('_JEXEC') or die('(@) | (@)');
/**
* Script file of HelloWorld module
*/
class mod_blz_k2_admin_menuInstallerScript {
/**
* Method to install the extension
* $parent is the class calling this method
*
* @return void
*/
function install($parent) {
}
/**
* Method to uninstall the extension
* $parent is the class calling this method
*
* @return void
*/
function uninstall($parent) {
}
/**
* Method to update the extension
* $parent is the class calling this method
*
* @return void
*/
function update($parent) {
}
/**
* Method to run before an install/update/uninstall method
* $parent is the class calling this method
* $type is the type of change (install, update or discover_install)
*
* @return void
*/
function preflight($type, $parent) {
// BEGIN Fix description for Joomla 2.5
if (version_compare(JVERSION, 3, '<')) {
$manifest = $parent->get('manifest');
$manifestDesc = $manifest->description->data();
if ($manifestDesc == 'MOD_BLZ_K2_ADMIN_MENU_XML_DESCRIPTION') {
$lang = JFactory::getLanguage();
$extension = 'mod_blz_k2_admin_menu';
$base_dir = dirname(__FILE__);
$language_tag = 'en-GB';
$reload = true;
$lang->load($extension, $base_dir, $language_tag, $reload);
$realManifestDesc = JText::_('MOD_BLZ_K2_ADMIN_MENU_XML_DESCRIPTION');
$manifest->description = $realManifestDesc;
$parent->set('manifest', $manifest);
}
// END Fix description for Joomla 2.5
}
}
/**
* Method to run after an install/update/uninstall method
* $parent is the class calling this method
* $type is the type of change (install, update or discover_install)
*
* @return void
*/
function postflight($type, $parent) {
$app = JFactory::getApplication();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*')
->from('#__modules')
->where('module = ' . $db->quote('mod_blz_k2_admin_menu'))
;
$db->setQuery($query)->execute();
$moduleRecords = $db->loadObjectList();
$doInsert = false;
$doUpdate = false;
switch (count($moduleRecords)) {
case 0: // Insert
$doInsert = true;
$insertObject = new stdClass();
$insertObject->id = null;
$insertObject->title = 'Blazing K2 Admin menu';
$insertObject->note = '';
$insertObject->content = '';
$insertObject->ordering = 0;
$insertObject->position = 'menu';
$insertObject->checked_out = 0;
$insertObject->checked_out_time = '0000-00-00 00:00:00';
$insertObject->publish_up = '0000-00-00 00:00:00';
$insertObject->publish_down = '0000-00-00 00:00:00';
$insertObject->published = 1;
$insertObject->module = 'mod_blz_k2_admin_menu';
$insertObject->access = 1;
$insertObject->showtitle = 0;
$insertObject->params = '';
$insertObject->client_id = 1;
$insertObject->language = '*';
break;
case 1: // Update enable
$doUpdate = true;
$updateObject = $moduleRecords[0];
$updateObject->published = 1;
$updateObject->position = 'menu';
$updateObject->showtitle = 0;
default: // More then one instane... Don't check anything....
}
if ($doInsert === true) {
if ($db->insertObject('#__modules', $insertObject)) {
$insertId = $db->insertid();
$app->enqueueMessage('Blazing K2 Admin module was auto enabled. You can change settings by going to Administrator modules or <a href="index.php?option=com_modules&task=module.edit&id=' . $insertId . '">click here</a>.');
} else
$app->enqueueMessage('There was an error when trying to auto enable the module. Please go to Modules, switch to administrator modules and open/publish/save it.');
}
if ($doUpdate === true) {
if ($db->updateObject('#__modules', $updateObject, 'id')) {
$app->enqueueMessage('Blazing K2 Admin module was auto enabled. You can change settings by going to Administrator modules or <a href="index.php?option=com_modules&task=module.edit&id=' . $updateObject->id . '" style="text-decoration: underline;">click here</a>.');
} else
$app->enqueueMessage('There was an error when trying to auto enable the module. Please go to Modules, switch to administrator modules and open/publish/save it.');
}
// Check if we have entry in modules_menu
if ($doInsert || $doUpdate) {
$query = $db->getQuery(true);
$query->select('*')
->from('#__modules_menu')
->where('moduleid = ' . (isset($insertId) ? $insertId : $updateObject->id) . ' AND menuid = 0')
;
$db->setQuery($query)->execute();
$menuEntries = $db->loadObjectList();
if (count($menuEntries) === 0)
$db->setQuery('INSERT INTO `#__modules_menu` (`moduleid` ,`menuid`) VALUES (' . (isset($insertId) ? $insertId : $updateObject->id) . ', 0);')->execute();
}
}
}