diff --git a/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-04-22.sql b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-04-22.sql new file mode 100644 index 0000000000000..9459c3d8abaaa --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-04-22.sql @@ -0,0 +1,8 @@ +ALTER TABLE `#__contact_details` MODIFY `publish_up` datetime NULL DEFAULT NULL; +ALTER TABLE `#__contact_details` MODIFY `publish_down` datetime NULL DEFAULT NULL; +ALTER TABLE `#__contact_details` MODIFY `checked_out_time` datetime NULL DEFAULT NULL; + +UPDATE `#__contact_details` SET + `publish_up` = CASE WHEN `publish_up` IN ('0000-00-00 00:00:00', '1000-01-01 00:00:00') THEN NULL ELSE `publish_up` END, + `publish_down` = CASE WHEN `publish_down` IN ('0000-00-00 00:00:00', '1000-01-01 00:00:00') THEN NULL ELSE `publish_down` END, + `checked_out_time` = CASE WHEN `checked_out_time` IN ('0000-00-00 00:00:00', '1000-01-01 00:00:00') THEN NULL ELSE `checked_out_time` END; diff --git a/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-04-22.sql b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-04-22.sql new file mode 100644 index 0000000000000..32d91acc14636 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-04-22.sql @@ -0,0 +1,13 @@ +ALTER TABLE "#__contact_details" ALTER COLUMN "publish_up" DROP NOT NULL; +ALTER TABLE "#__contact_details" ALTER COLUMN "publish_up" DROP DEFAULT; + +ALTER TABLE "#__contact_details" ALTER COLUMN "publish_down" DROP NOT NULL; +ALTER TABLE "#__contact_details" ALTER COLUMN "publish_down" DROP DEFAULT; + +ALTER TABLE "#__contact_details" ALTER COLUMN "checked_out_time" DROP NOT NULL; +ALTER TABLE "#__contact_details" ALTER COLUMN "checked_out_time" DROP DEFAULT; + +UPDATE "#__contact_details" SET + "publish_up" = CASE WHEN "publish_up" = '1970-01-01 00:00:00' THEN NULL ELSE "publish_up" END, + "publish_down" = CASE WHEN "publish_down" = '1970-01-01 00:00:00' THEN NULL ELSE "publish_down" END, + "checked_out_time" = CASE WHEN "checked_out_time" = '1970-01-01 00:00:00' THEN NULL ELSE "checked_out_time" END; diff --git a/administrator/components/com_contact/Table/ContactTable.php b/administrator/components/com_contact/Table/ContactTable.php index 64d7dee246efa..04f53ce83dc45 100644 --- a/administrator/components/com_contact/Table/ContactTable.php +++ b/administrator/components/com_contact/Table/ContactTable.php @@ -27,6 +27,14 @@ */ class ContactTable extends Table { + /** + * Indicates that columns fully support the NULL value in the database + * + * @var boolean + * @since __DEPLOY_VERSION__ + */ + protected $_supportNullValue = true; + /** * Ensure the params and metadata in json encoded in the bind method * @@ -58,7 +66,7 @@ public function __construct(DatabaseDriver $db) * * @since 1.6 */ - public function store($updateNulls = false) + public function store($updateNulls = true) { // Transform the params field if (is_array($this->params)) @@ -91,18 +99,6 @@ public function store($updateNulls = false) } } - // Set publish_up to null date if not set - if (!$this->publish_up) - { - $this->publish_up = $this->_db->getNullDate(); - } - - // Set publish_down to null date if not set - if (!$this->publish_down) - { - $this->publish_down = $this->_db->getNullDate(); - } - // Set xreference to empty string if not set if (!$this->xreference) { @@ -253,9 +249,20 @@ public function check() $this->metadata = '{}'; } - if (empty($this->modified)) + // Set publish_up, publish_down to null if not set + if (!$this->publish_up) + { + $this->publish_up = null; + } + + if (!$this->publish_down) + { + $this->publish_down = null; + } + + if (!$this->modified) { - $this->modified = $this->getDbo()->getNullDate(); + $this->modified = $this->created; } return true; diff --git a/components/com_contact/Model/CategoryModel.php b/components/com_contact/Model/CategoryModel.php index bbfb193c941bd..02e32764fdb83 100644 --- a/components/com_contact/Model/CategoryModel.php +++ b/components/com_contact/Model/CategoryModel.php @@ -180,8 +180,8 @@ protected function getListQuery() if ($this->getState('filter.publish_date')) { - $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')') - ->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); + $query->where('(' . $query->isNullDatetime('a.publish_up') . ' OR a.publish_up <= ' . $db->quote($nowDate) . ')') + ->where('(' . $query->isNullDatetime('a.publish_down') . ' OR a.publish_down >= ' . $db->quote($nowDate) . ')'); } // Filter by search in title diff --git a/components/com_contact/Model/ContactModel.php b/components/com_contact/Model/ContactModel.php index 13d83d9a5f159..f8a8368ec961c 100644 --- a/components/com_contact/Model/ContactModel.php +++ b/components/com_contact/Model/ContactModel.php @@ -215,8 +215,8 @@ public function getItem($pk = null) if (is_numeric($published)) { $query->where('(a.published = ' . (int) $published . ' OR a.published =' . (int) $archived . ')') - ->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')') - ->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); + ->where('(' . $query->isNullDatetime('a.publish_up') . ' OR a.publish_up <= ' . $db->quote($nowDate) . ')') + ->where('(' . $query->isNullDatetime('a.publish_down') . ' OR a.publish_down >= ' . $db->quote($nowDate) . ')'); } $db->setQuery($query); diff --git a/components/com_contact/Model/FeaturedModel.php b/components/com_contact/Model/FeaturedModel.php index 1a2148f228edb..96c4129265070 100644 --- a/components/com_contact/Model/FeaturedModel.php +++ b/components/com_contact/Model/FeaturedModel.php @@ -118,8 +118,8 @@ protected function getListQuery() $date = Factory::getDate(); $nowDate = $db->quote($date->toSql()); - $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')') - ->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); + $query->where('(' . $query->isNullDatetime('a.publish_up') . ' OR a.publish_up <= ' . $db->quote($nowDate) . ')') + ->where('(' . $query->isNullDatetime('a.publish_down') . ' OR a.publish_down >= ' . $db->quote($nowDate) . ')'); } // Filter by language diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index 3972a2bc9691f..0d478573183cb 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -283,7 +283,7 @@ CREATE TABLE IF NOT EXISTS `#__contact_details` ( `default_con` tinyint(1) unsigned NOT NULL DEFAULT 0, `published` tinyint(1) NOT NULL DEFAULT 0, `checked_out` int(10) unsigned NOT NULL DEFAULT 0, - `checked_out_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `checked_out_time` datetime, `ordering` int(11) NOT NULL DEFAULT 0, `params` text NOT NULL, `user_id` int(11) NOT NULL DEFAULT 0, @@ -305,8 +305,8 @@ CREATE TABLE IF NOT EXISTS `#__contact_details` ( `metadata` text NOT NULL, `featured` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT 'Set if contact is featured.', `xreference` varchar(50) NOT NULL DEFAULT '' COMMENT 'A reference to enable linkages to external data sets.', - `publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - `publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `publish_up` datetime, + `publish_down` datetime, `version` int(10) unsigned NOT NULL DEFAULT 1, `hits` int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (`id`), diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index 8c3f062647995..80246996cb80c 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -288,7 +288,7 @@ CREATE TABLE IF NOT EXISTS "#__contact_details" ( "default_con" smallint NOT NULL DEFAULT 0, "published" smallint NOT NULL DEFAULT 0, "checked_out" bigint NOT NULL DEFAULT 0, - "checked_out_time" timestamp without time zone NOT NULL DEFAULT '1970-01-01 00:00:00', + "checked_out_time" timestamp without time zone, "ordering" bigint NOT NULL DEFAULT 0, "params" text NOT NULL, "user_id" bigint NOT NULL DEFAULT 0, @@ -310,8 +310,8 @@ CREATE TABLE IF NOT EXISTS "#__contact_details" ( "metadata" text NOT NULL, "featured" smallint NOT NULL DEFAULT 0, "xreference" varchar(50) NOT NULL DEFAULT '', - "publish_up" timestamp without time zone NOT NULL DEFAULT '1970-01-01 00:00:00', - "publish_down" timestamp without time zone NOT NULL DEFAULT '1970-01-01 00:00:00', + "publish_up" timestamp without time zone, + "publish_down" timestamp without time zone, "version" bigint NOT NULL DEFAULT 1, "hits" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("id")