Skip to content

Commit

Permalink
Merge branch 'rework-sql-default-values' into joomla_5.x: Reworked SQ…
Browse files Browse the repository at this point in the history
…L commands. Fixes #46, #49, #50, #58. Improves earlier fixes for #19, #27, #37, #38.
  • Loading branch information
Jefferson49 committed Nov 4, 2023
2 parents be51044 + 5f7fd90 commit 2b3a3c3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 124 deletions.
74 changes: 37 additions & 37 deletions com_sexypolling/admin/install/sql/install.sql
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
CREATE TABLE IF NOT EXISTS `#__sexy_polls` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_user` int(10) unsigned NOT NULL,
`id_category` mediumint(8) unsigned NOT NULL,
`id_template` mediumint(8) unsigned NOT NULL,
`id_user` int(10) unsigned NOT NULL DEFAULT '0',
`id_category` mediumint(8) unsigned NOT NULL DEFAULT '1',
`id_template` mediumint(8) unsigned NOT NULL DEFAULT '1',
`name` text NOT NULL,
`alias` text NOT NULL,
`question` text NOT NULL,
`created` datetime NOT NULL,
`date_start` date NOT NULL,
`date_end` date NOT NULL,
`created` datetime NOT NULL DEFAULT NOW(),
`date_start` date NOT NULL DEFAULT NOW(),
`date_end` date NOT NULL DEFAULT '2040-12-31',
`showresultsduringpoll` tinyint(3) unsigned NOT NULL DEFAULT '1',
`publish_up` datetime NOT NULL,
`publish_down` datetime NOT NULL,
`published` tinyint(1) NOT NULL,
`checked_out` int(10) unsigned NULL DEFAULT NULL,
`checked_out_time` datetime NOT NULL,
`access` int(10) unsigned NOT NULL,
`featured` tinyint(3) unsigned NOT NULL,
`ordering` int(11) NOT NULL,
`language` char(7) NOT NULL,
`publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`published` tinyint(1) NOT NULL DEFAULT '1',
`checked_out` int(10) unsigned NOT NULL DEFAULT '0',
`checked_out_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`access` int(10) unsigned NOT NULL DEFAULT '1',
`featured` tinyint(3) unsigned NOT NULL DEFAULT '0',
`ordering` int(11) NOT NULL DEFAULT '0',
`language` char(7) NOT NULL DEFAULT '',
`multiple_answers` enum('0','1') NOT NULL DEFAULT '0',
`voting_permission` int(10) unsigned NOT NULL DEFAULT '1',
`number_answers` mediumint(8) unsigned NOT NULL,
`voting_period` float unsigned NOT NULL,
`number_answers` mediumint(8) unsigned NOT NULL DEFAULT '0',
`voting_period` float unsigned NOT NULL DEFAULT '24',
`answerpermission` int(10) unsigned NOT NULL DEFAULT '1',
`autopublish` enum('0','1') NOT NULL DEFAULT '1',
`baranimationtype` text NOT NULL,
Expand Down Expand Up @@ -65,16 +65,16 @@ INSERT IGNORE INTO `#__sexy_polls` (`id`, `id_user`, `id_category`, `id_template

CREATE TABLE IF NOT EXISTS `#__sexy_answers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_poll` int(10) unsigned NOT NULL,
`id_poll` int(10) unsigned NOT NULL DEFAULT '1',
`id_user` int(10) unsigned NOT NULL DEFAULT '0',
`name` text NOT NULL,
`published` tinyint(1) NOT NULL,
`publish_up` datetime NOT NULL,
`publish_down` datetime NOT NULL,
`created` datetime NOT NULL,
`ordering` mediumint(8) unsigned NOT NULL,
`published` tinyint(1) NOT NULL DEFAULT '1',
`publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT NOW(),
`ordering` mediumint(8) unsigned NOT NULL DEFAULT '0',
`show_name` TINYINT UNSIGNED NOT NULL DEFAULT '1',
`img_width` INT UNSIGNED NOT NULL DEFAULT '100',
`img_width` INT UNSIGNED NOT NULL DEFAULT '100',
`img_name` TEXT NOT NULL,
`img_url` TEXT NOT NULL,
`embed` TEXT NOT NULL,
Expand All @@ -93,14 +93,14 @@ INSERT IGNORE INTO `#__sexy_answers` (`id`, `id_poll`, `id_user`, `name`, `publi

CREATE TABLE IF NOT EXISTS `#__sexy_votes` (
`id_vote` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_answer` int(10) unsigned NOT NULL,
`id_answer` int(10) unsigned NOT NULL DEFAULT '1',
`id_user` int(10) unsigned NOT NULL DEFAULT '0',
`ip` text NOT NULL,
`date` datetime NOT NULL,
`country` text NOT NULL DEFAULT 'Unknown',
`city` text NOT NULL DEFAULT 'Unknown',
`region` text NOT NULL DEFAULT 'Unknown',
`countrycode` text NOT NULL DEFAULT 'Unknown',
`date` datetime NOT NULL DEFAULT NOW(),
`country` text NOT NULL,
`city` text NOT NULL,
`region` text NOT NULL,
`countrycode` text NOT NULL,
PRIMARY KEY (`id_vote`),
KEY `id_answer` (`id_answer`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Expand Down Expand Up @@ -358,10 +358,10 @@ INSERT IGNORE INTO `#__sexy_votes` (`id_answer`, `ip`, `date`,`country`,`city`,`
CREATE TABLE IF NOT EXISTS `#__sexy_categories` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
`published` tinyint(1) NOT NULL,
`publish_up` datetime NOT NULL,
`publish_down` datetime NOT NULL,
`ordering` mediumint(8) unsigned NOT NULL,
`published` tinyint(1) NOT NULL DEFAULT '1',
`publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`ordering` mediumint(8) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM CHARACTER SET = `utf8`;

Expand All @@ -372,9 +372,9 @@ CREATE TABLE IF NOT EXISTS `#__sexy_templates` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
`styles` text NOT NULL,
`published` tinyint(1) NOT NULL DEFAULT '0',
`publish_up` datetime NOT NULL,
`publish_down` datetime NOT NULL,
`published` tinyint(1) NOT NULL DEFAULT '1',
`publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=MyISAM CHARACTER SET = `utf8`;

Expand Down
2 changes: 1 addition & 1 deletion com_sexypolling/admin/models/sexyanswer.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function saveAnswer()
//add votes
$res = (int) $jform['insert_votes'];
if($res > 0) {
$query = 'INSERT INTO `#__sexy_votes` (`id_answer`, `ip`, `date`) VALUES ';
$query = 'INSERT IGNORE INTO `#__sexy_votes` (`id_answer`, `ip`, `date`) VALUES ';
for($i = 0; $i < $res; $i ++) {
$query .= '('.$id.', \'\', ' . HTMLHelper::date("now", "Y-m-d H:i:s", 'UTC') . ')';
if($i != $res - 1)
Expand Down
122 changes: 36 additions & 86 deletions com_sexypolling/scriptfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,6 @@ function uninstall($parent) {

//we do not need to uninstall the module and plugin, because it is handled by Joomla already
return;

/*
$db = Factory::getDBO();
// uninstalling sexy polling module
$sql = 'SELECT `extension_id` AS id, `name`, `element`, `folder` FROM #__extensions WHERE `type` = "module" AND ( (`element` = "mod_sexypolling") ) ';
$db->setQuery($sql);
$sexy_polling_module = $db->loadObject();
$module_uninstaller = new Installer;
$module_uninstaller->uninstall('module', $sexy_polling_module->id);
// uninstalling sexy polling plugin
$db->setQuery("select extension_id from #__extensions where name = 'PLG_SEXYPOLLING' and type = 'plugin' and element = 'sexypolling'");
$cis_plugin = $db->loadObject();
$plugin_uninstaller = new Installer;
$plugin_uninstaller->uninstall('plugin', $cis_plugin->extension_id);
*/
}

/**
Expand Down Expand Up @@ -107,13 +90,14 @@ function update($parent) {

/**
* method to run before an install/update/uninstall method
*
*
* @param $parent is the class calling this method
* @param $type is the type of change (install, update or discover_install)
*
* @return void
*/
function preflight($type, $parent) {
// $parent is the class calling this method
// $type is the type of change (install, update or discover_install)
//echo '<p>' . Text::_('COM_HELLOWORLD_PREFLIGHT_' . $type . '_TEXT') . '</p>';
return;
}

/**
Expand All @@ -138,28 +122,28 @@ function postflight($type, $parent) {
//add required columns
$query_update = "
ALTER TABLE `#__sexy_polls`
ADD `showvotesperiod` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `stringdateformat` TEXT NOT NULL,
ADD `votescountformat` TINYINT UNSIGNED NOT NULL DEFAULT '2',
ADD `scaledefault` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `showaddanswericon` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `showscaleicon` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `showbackicon` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `showtimelineicon` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `showtimeline` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `showvotescountinfo` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `poll_width` TEXT NOT NULL,
ADD `pollalign` TINYINT UNSIGNED NOT NULL DEFAULT '2',
ADD `addclearboth` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `poll_margintop` SMALLINT UNSIGNED NOT NULL DEFAULT '5',
ADD `poll_marginbottom` SMALLINT UNSIGNED NOT NULL DEFAULT '5',
ADD `poll_marginleft` SMALLINT UNSIGNED NOT NULL DEFAULT '5',
ADD `poll_marginright` SMALLINT UNSIGNED NOT NULL DEFAULT '5',
ADD `classsuffix` TEXT NOT NULL,
ADD `checktoken` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `ipcount` INT UNSIGNED NOT NULL DEFAULT '0',
ADD `checkacl` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `votechecks` TINYINT UNSIGNED NOT NULL DEFAULT '0'
ADD `showvotesperiod` tinyint unsigned NOT NULL DEFAULT '1',
ADD `stringdateformat` text NOT NULL,
ADD `votescountformat` tinyint unsigned NOT NULL DEFAULT '2',
ADD `scaledefault` tinyint unsigned NOT NULL DEFAULT '1',
ADD `showaddanswericon` tinyint unsigned NOT NULL DEFAULT '1',
ADD `showscaleicon` tinyint unsigned NOT NULL DEFAULT '1',
ADD `showbackicon` tinyint unsigned NOT NULL DEFAULT '1',
ADD `showtimelineicon` tinyint unsigned NOT NULL DEFAULT '1',
ADD `showtimeline` tinyint unsigned NOT NULL DEFAULT '1',
ADD `showvotescountinfo` tinyint unsigned NOT NULL DEFAULT '1',
ADD `poll_width` text NOT NULL,
ADD `pollalign` tinyint unsigned NOT NULL DEFAULT '2',
ADD `addclearboth` tinyint unsigned NOT NULL DEFAULT '1',
ADD `poll_margintop` smallint unsigned NOT NULL DEFAULT '5',
ADD `poll_marginbottom` smallint unsigned NOT NULL DEFAULT '5',
ADD `poll_marginleft` smallint unsigned NOT NULL DEFAULT '5',
ADD `poll_marginright` smallint unsigned NOT NULL DEFAULT '5',
ADD `classsuffix` text NOT NULL,
ADD `checktoken` tinyint unsigned NOT NULL DEFAULT '1',
ADD `ipcount` INT unsigned NOT NULL DEFAULT '0',
ADD `checkacl` tinyint unsigned NOT NULL DEFAULT '1',
ADD `votechecks` tinyint unsigned NOT NULL DEFAULT '0'
";
$db->setQuery($query_update);
$db->execute();
Expand All @@ -171,16 +155,16 @@ function postflight($type, $parent) {

$query_update = "
ALTER TABLE `#__sexy_answers`
ADD `show_name` TINYINT UNSIGNED NOT NULL DEFAULT '1',
ADD `img_width` INT UNSIGNED NOT NULL DEFAULT '100',
ADD `img_name` TEXT NOT NULL,
ADD `img_url` TEXT NOT NULL,
ADD `embed` TEXT NOT NULL
ADD `show_name` tinyint unsigned NOT NULL DEFAULT '1',
ADD `img_width` INT unsigned NOT NULL DEFAULT '100',
ADD `img_name` text NOT NULL,
ADD `img_url` text NOT NULL,
ADD `embed` text NOT NULL
";
$db->setQuery($query_update);
$db->execute();

$query_update = "ALTER TABLE `#__sexy_votes` ADD `id_user` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `id_answer`";
$query_update = "ALTER TABLE `#__sexy_votes` ADD `id_user` INT unsigned NOT NULL DEFAULT '0' AFTER `id_answer`";
$db->setQuery($query_update);
$db->execute();
}
Expand All @@ -200,7 +184,7 @@ function postflight($type, $parent) {
if(is_array($columns_titles)) {
if(!in_array('id_vote', $columns_titles)) {
//add required columns
$query_update = "alter table #__sexy_votes add column id_vote int(10) unsigned primary key NOT NULL AUTO_INCREMENT FIRST";
$query_update = "alter table #__sexy_votes ADD COLUMN id_vote int(10) unsigned PRIMARY KEY NOT NULL AUTO_INCREMENT FIRST";
$db->setQuery($query_update);
$db->execute();
}
Expand All @@ -216,7 +200,7 @@ function postflight($type, $parent) {
if(is_array($columns_titles)) {
if($columns_data['Null'] === "NO") {
$query_update = "
ALTER TABLE `#__sexy_polls` CHANGE `checked_out` `checked_out` INT(10) UNSIGNED NULL DEFAULT NULL
ALTER TABLE `#__sexy_polls` MODIFY `checked_out` int(10) unsigned NOT NULL DEFAULT 0
";
$db->setQuery($query_update);
$db->execute();
Expand All @@ -231,46 +215,12 @@ function postflight($type, $parent) {
if(is_array($columns_titles)) {
if($columns_data['Default'] != "0") {
$query_update = "
ALTER TABLE `#__sexy_answers` ALTER `id_user` SET DEFAULT ('0')
ALTER TABLE `#__sexy_answers` MODIFY `id_user` int(10) unsigned NOT NULL DEFAULT 0
";
$db->setQuery($query_update);
$db->execute();
}
}

$query = "SHOW COLUMNS FROM #__sexy_votes LIKE 'country'";
$db->setQuery($query);
$columns_data = $db->LoadAssoc();
$columns_titles = array_keys($columns_data);

if(is_array($columns_titles)) {
if($columns_data['Default'] != "Unknown") {

$query_update = "
ALTER TABLE `#__sexy_votes` ALTER `country` SET DEFAULT ('Unknown')
";
$db->setQuery($query_update);
$db->execute();

$query_update = "
ALTER TABLE `#__sexy_votes` ALTER `countrycode` SET DEFAULT ('Unknown')
";
$db->setQuery($query_update);
$db->execute();

$query_update = "
ALTER TABLE `#__sexy_votes` ALTER `city` SET DEFAULT ('Unknown')
";
$db->setQuery($query_update);
$db->execute();

$query_update = "
ALTER TABLE `#__sexy_votes` ALTER `region` SET DEFAULT ('Unknown')
";
$db->setQuery($query_update);
$db->execute();
}
}

}
}

0 comments on commit 2b3a3c3

Please sign in to comment.