Skip to content

Commit

Permalink
[4.0] [com_menus] Nullable datetime columns in database (#26435)
Browse files Browse the repository at this point in the history
  • Loading branch information
richard67 authored and wilsonge committed Oct 3, 2019
1 parent f3dbcac commit 0f63c55
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
ALTER TABLE `#__menu` ADD COLUMN `publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00';
ALTER TABLE `#__menu` ADD COLUMN `publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00';
ALTER TABLE `#__menu` ADD COLUMN `publish_up` datetime;
ALTER TABLE `#__menu` ADD COLUMN `publish_down` datetime;

ALTER TABLE `#__menu` MODIFY `checked_out_time` datetime NULL DEFAULT NULL;

UPDATE `#__menu` SET `checked_out_time` = NULL WHERE `checked_out_time` = '0000-00-00 00:00:00';
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
INSERT INTO `#__menu` (`menutype`, `title`, `alias`, `note`, `path`, `link`, `type`, `published`, `parent_id`, `level`, `component_id`, `checked_out`, `checked_out_time`, `browserNav`, `access`, `img`, `template_style_id`, `params`, `lft`, `rgt`, `home`, `language`, `client_id`, `publish_up`, `publish_down`) VALUES ('main', 'com_messages_manager', 'Private Messages', '', 'Messaging/Private Messages', 'index.php?option=com_messages&view=messages', 'component', 1, 10, 2, 15, 0, '0000-00-00 00:00:00', 0, 0, 'class:messages', 0, '', 17, 20, 0, '*', 1, '0000-00-00 00:00:00', '0000-00-00 00:00:00');
INSERT INTO `#__menu` (`menutype`, `title`, `alias`, `note`, `path`, `link`, `type`, `published`, `parent_id`, `level`, `component_id`, `checked_out`, `checked_out_time`, `browserNav`, `access`, `img`, `template_style_id`, `params`, `lft`, `rgt`, `home`, `language`, `client_id`, `publish_up`, `publish_down`)
SELECT 'main', 'com_messages_manager', 'Private Messages', '', 'Messaging/Private Messages', 'index.php?option=com_messages&view=messages', 'component', 1, 10, 2, `extension_id`, 0, NULL, 0, 0, 'class:messages-add', 0, '', 18, 19, 0, '*', 1, NULL, NULL FROM `#__extensions` WHERE `name` = 'com_messages';
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
ALTER TABLE "#__menu" ADD COLUMN "publish_up" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL;
ALTER TABLE "#__menu" ADD COLUMN "publish_down" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL;
ALTER TABLE "#__menu" ADD COLUMN "publish_up" timestamp without time zone;
ALTER TABLE "#__menu" ADD COLUMN "publish_down" timestamp without time zone;

ALTER TABLE "#__menu" ALTER COLUMN "checked_out_time" DROP NOT NULL;
ALTER TABLE "#__menu" ALTER COLUMN "checked_out_time" DROP DEFAULT;

UPDATE "#__menu" SET "checked_out_time" = NULL WHERE "checked_out_time" = '1970-01-01 00:00:00';
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSERT INTO "#__menu" ("menutype", "title", "alias", "note", "path", "link", "type", "published", "parent_id", "level", "component_id", "checked_out", "checked_out_time", "browserNav", "access", "img", "template_style_id", "params", "lft", "rgt", "home", "language", "client_id")
SELECT 'main', 'com_messages_manager', 'Private Messages', '', 'Messaging/Private Messages', 'index.php?option=com_messages&view=messages', 'component', 1, 10, 2, "extension_id", 0, '1970-01-01 00:00:00', 0, 0, 'class:messages-add', 0, '', 18, 19, 0, '*', 1 FROM "#__extensions" WHERE "name" = 'com_messages';
INSERT INTO "#__menu" ("menutype", "title", "alias", "note", "path", "link", "type", "published", "parent_id", "level", "component_id", "checked_out", "checked_out_time", "browserNav", "access", "img", "template_style_id", "params", "lft", "rgt", "home", "language", "client_id", "publish_up", "publish_down")
SELECT 'main', 'com_messages_manager', 'Private Messages', '', 'Messaging/Private Messages', 'index.php?option=com_messages&view=messages', 'component', 1, 10, 2, "extension_id", 0, NULL, 0, 0, 'class:messages-add', 0, '', 18, 19, 0, '*', 1, NULL, NULL FROM "#__extensions" WHERE "name" = 'com_messages';
12 changes: 5 additions & 7 deletions administrator/components/com_menus/Table/MenuTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,20 @@ public function check()

if ($return)
{
$db = Factory::getDbo();

// Set publish_up to null date if not set
if (!$this->publish_up)
{
$this->publish_up = $db->getNullDate();
$this->publish_up = null;
}

// Set publish_down to null date if not set
if (!$this->publish_down)
{
$this->publish_down = $db->getNullDate();
$this->publish_down = null;
}

// Check the publish down date is not earlier than publish up.
if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up)
if (!is_null($this->publish_down) && !is_null($this->publish_up) && $this->publish_down < $this->publish_up)
{
$this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));

Expand All @@ -88,8 +86,8 @@ public function check()
if ((int) $this->home)
{
// Set the publish down/up always for home.
$this->publish_up = $db->getNullDate();
$this->publish_down = $db->getNullDate();
$this->publish_up = null;
$this->publish_down = null;
}
}

Expand Down
Loading

0 comments on commit 0f63c55

Please sign in to comment.