| Current Path : /home/g/i/t/giteleslfp/www/administrator/components/com_templateck/ |
| Current File : /home/g/i/t/giteleslfp/www/administrator/components/com_templateck/install.templateck.php |
<?php
/**
* @name Template Creator CK
* @copyright Copyright (C) since 2011. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @author Cedric Keiflin - http://www.template-creator.com - http://www.joomlack.fr
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
class com_templateckInstallerScript {
function preflight() {
$db = JFactory::getDbo();
$tablesList = $db->getTableList();
$tableExists = in_array($db->getPrefix() . 'templateck_templates', $tablesList);
if ($tableExists) {
$this->updateTable350();
$this->updateTable399();
$this->updateTable400();
}
}
function update( $parent ) {
// check the installed version
$oldversion = $this->getParam('version');
if (version_compare($oldversion, '4.0.0') < 0) {
$this->updateTable400();
}
if (version_compare($oldversion, '3.5.0') < 0) {
$this->updateTable350();
}
if (version_compare($oldversion, '3.4.4') >= 0) {
//echo 'Update script loaded you have the last version';
return;
}
// this is an old version, then update the table
$this->updateTable();
}
/*
* get a variable from the manifest file (actually, from the manifest cache).
*/
function getParam( $name ) {
$db = JFactory::getDbo();
$db->setQuery('SELECT manifest_cache FROM #__extensions WHERE element = "com_templateck"');
$manifest = json_decode( $db->loadResult(), true );
return $manifest[ $name ];
}
/*
* update the table
*/
function updateTable() {
$db = JFactory::getDbo();
// test for order column title depending on virtuemart version
// test if the columns not exists
$query = "SHOW COLUMNS FROM #__templateck_fonts LIKE 'additional_fonts'";
$db->setQuery($query);
if ($db->execute()) {
if ( $db->loadResult()) {
//echo 'existe deja!';return;
} else {
// add the SQL field to the main table
$db->setQuery('ALTER TABLE `#__templateck_fonts` ADD `additional_fonts` text NOT NULL;');
if (!$db->execute()) {
echo '<p class="alert alert-danger">Error during table templateck update process !</p>';
} else {
echo '<p class="alert alert-success">Table templateck_fonts updated !</p>';
}
}
} else {
echo 'Erreur de données SQL - Test si champ responsive existe';
return false;
}
}
/*
* update the table
*/
function updateTable350() {
$db = JFactory::getDbo();
// test if the columns not exists
$query = "SHOW COLUMNS FROM #__templateck_templates LIKE 'widgets'";
$db->setQuery($query);
if ($db->execute()) {
if ( $db->loadResult()) {
//echo 'existe deja!';return;
} else {
// add the SQL field to the main table
$db->setQuery('ALTER TABLE `#__templateck_templates` ADD `widgets` text NOT NULL;');
if (!$db->execute()) {
echo '<p class="alert alert-danger">Error during table widgets update process !</p>';
} else {
echo '<p class="alert alert-success">Table widgets updated !</p>';
}
}
} else {
echo 'SQL error - Check existing widgets column';
return false;
}
}
/*
* update the table
*/
function updateTable399() {
$db = JFactory::getDbo();
// test if the columns not exists
$query = "SHOW COLUMNS FROM #__templateck_templates LIKE 'modules'";
$db->setQuery($query);
if ($db->execute()) {
if ( $db->loadResult()) {
//echo 'existe deja!';return;
} else {
// add the SQL field to the main table
$db->setQuery('ALTER TABLE `#__templateck_templates` ADD `modules` text NOT NULL;');
if (!$db->execute()) {
echo '<p class="alert alert-danger">Error during table modules update process !</p>';
} else {
echo '<p class="alert alert-success">Table modules updated !</p>';
}
}
} else {
echo 'SQL error - Check existing modules column';
return false;
}
}
function updateTable400() {
$db = JFactory::getDbo();
// test if the columns not exists
$query = "SHOW COLUMNS FROM #__templateck_templates LIKE 'stylecode'";
$db->setQuery($query);
if ($db->execute()) {
if ( $db->loadResult()) {
//echo 'existe deja!';return;
} else {
// add the SQL field to the main table
$db->setQuery('ALTER TABLE `#__templateck_templates` ADD `stylecode` longtext NOT NULL;');
if (!$db->execute()) {
echo '<p class="alert alert-danger">Error during table stylecode update process !</p>';
} else {
echo '<p class="alert alert-success">Table stylecode updated !</p>';
}
}
} else {
// echo 'SQL error - Check existing stylecode column';
// return false;
}
$sql = "CREATE TABLE IF NOT EXISTS `#__templateck_layouts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_id` int(11) NOT NULL,
`type` text NOT NULL,
`htmlcode` longtext NOT NULL,
`styles` text NOT NULL,
`published` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
);";
$db->setQuery($query);
if ($db->execute()) {
echo '<p class="alert alert-success">Table layouts created !</p>';
} else {
echo '<p class="alert alert-danger">Error during table layouts creation process !</p>';
}
}
}