Real null datetimes for weblinks 4.0

This commit is contained in:
Richard Fath 2021-08-15 13:30:47 +02:00
parent efa61dea5b
commit 520a1ec6a1
6 changed files with 106 additions and 19 deletions

View File

@ -114,7 +114,7 @@ class Com_WeblinksInstallerScript
$category->metadesc = '';
$category->metakey = '';
$category->language = '*';
$category->checked_out_time = Factory::getDbo()->getNullDate();
$category->checked_out_time = null;
$category->version = 1;
$category->hits = 0;
$category->modified_user_id = 0;

View File

@ -20,23 +20,23 @@ CREATE TABLE IF NOT EXISTS `#__weblinks` (
`hits` int NOT NULL DEFAULT 0,
`state` tinyint NOT NULL DEFAULT 0,
`checked_out` int NOT NULL DEFAULT 0,
`checked_out_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`checked_out_time` datetime,
`ordering` int NOT NULL DEFAULT 0,
`access` int NOT NULL DEFAULT 1,
`params` text NOT NULL,
`language` char(7) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL,
`created_by` int unsigned NOT NULL DEFAULT 0,
`created_by_alias` varchar(255) NOT NULL DEFAULT '',
`modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified` datetime NOT NULL,
`modified_by` int unsigned NOT NULL DEFAULT 0,
`metakey` text NOT NULL,
`metadesc` text NOT NULL,
`metadata` text NOT NULL,
`featured` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Set if link is featured.',
`xreference` varchar(50) NOT NULL 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 unsigned NOT NULL DEFAULT 1,
`images` text NOT NULL,
PRIMARY KEY (`id`),

View File

@ -18,23 +18,23 @@ CREATE TABLE "#__weblinks" (
"hits" bigint DEFAULT 0 NOT NULL,
"state" smallint DEFAULT 0 NOT NULL,
"checked_out" bigint DEFAULT 0 NOT NULL,
"checked_out_time" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"checked_out_time" timestamp without time zone,
"ordering" bigint DEFAULT 0 NOT NULL,
"access" bigint DEFAULT 1 NOT NULL,
"params" text NOT NULL,
"language" varchar(7) DEFAULT '' NOT NULL,
"created" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"created" timestamp without time zone NOT NULL,
"created_by" integer DEFAULT 0 NOT NULL,
"created_by_alias" varchar(255) DEFAULT '' NOT NULL,
"modified" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"modified" timestamp without time zone NOT NULL,
"modified_by" integer DEFAULT 0 NOT NULL,
"metakey" text NOT NULL,
"metadesc" text NOT NULL,
"metadata" text NOT NULL,
"featured" smallint DEFAULT 0 NOT NULL,
"xreference" varchar(50) NOT NULL,
"publish_up" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"publish_down" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"publish_up" timestamp without time zone,
"publish_down" timestamp without time zone,
"version" bigint DEFAULT 1 NOT NULL,
"images" text NOT NULL,
PRIMARY KEY ("id")

View File

@ -0,0 +1,31 @@
ALTER TABLE `#__weblinks` MODIFY `created` datetime NOT NULL;
ALTER TABLE `#__weblinks` MODIFY `modified` datetime NOT NULL;
ALTER TABLE `#__weblinks` MODIFY `publish_up` datetime NULL DEFAULT NULL;
ALTER TABLE `#__weblinks` MODIFY `publish_down` datetime NULL DEFAULT NULL;
ALTER TABLE `#__weblinks` MODIFY `checked_out_time` datetime NULL DEFAULT NULL;
UPDATE `#__weblinks` SET `modified` = `created` WHERE `modified` = '0000-00-00 00:00:00';
UPDATE `#__weblinks` SET `publish_up` = NULL WHERE `publish_up` = '0000-00-00 00:00:00';
UPDATE `#__weblinks` SET `publish_down` = NULL WHERE `publish_down` = '0000-00-00 00:00:00';
UPDATE `#__weblinks` SET `checked_out_time` = NULL WHERE `checked_out_time` = '0000-00-00 00:00:00';
UPDATE `#__categories` SET `modified_time` = `created_time` WHERE `modified_time` = '0000-00-00 00:00:00' AND `extension` = 'com_weblinks';
UPDATE `#__categories` SET `checked_out_time` = NULL WHERE `checked_out_time` = '0000-00-00 00:00:00' AND `extension` = 'com_weblinks';
UPDATE `#__ucm_content` SET `core_modified_time` = `core_created_time`
WHERE `core_type_alias` IN ('com_weblinks.weblink', 'com_weblinks.category')
AND `core_modified_time` = '0000-00-00 00:00:00';
UPDATE `#__ucm_content` SET `core_publish_up` = NULL
WHERE `core_type_alias` = 'com_weblinks.weblink'
AND `core_publish_up` = '0000-00-00 00:00:00';
UPDATE `#__ucm_content` SET `core_publish_down` = NULL
WHERE `core_type_alias` = 'com_weblinks.weblink'
AND `core_publish_down` = '0000-00-00 00:00:00';
UPDATE `#__ucm_content` SET `core_checked_out_time` = NULL
WHERE `core_type_alias` IN ('com_weblinks.weblink', 'com_weblinks.category')
AND `core_checked_out_time` = '0000-00-00 00:00:00';

View File

@ -0,0 +1,37 @@
ALTER TABLE "#__weblinks" ALTER COLUMN "created" DROP DEFAULT;
ALTER TABLE "#__weblinks" ALTER COLUMN "modified" DROP DEFAULT;
ALTER TABLE "#__weblinks" ALTER COLUMN "publish_up" DROP NOT NULL;
ALTER TABLE "#__weblinks" ALTER COLUMN "publish_up" DROP DEFAULT;
ALTER TABLE "#__weblinks" ALTER COLUMN "publish_down" DROP NOT NULL;
ALTER TABLE "#__weblinks" ALTER COLUMN "publish_down" DROP DEFAULT;
ALTER TABLE "#__weblinks" ALTER COLUMN "checked_out_time" DROP NOT NULL;
ALTER TABLE "#__weblinks" ALTER COLUMN "checked_out_time" DROP DEFAULT;
UPDATE "#__weblinks" SET "modified" = "created" WHERE "modified" = '1970-01-01 00:00:00';
UPDATE "#__weblinks" SET "publish_up" = NULL WHERE "publish_up" = '1970-01-01 00:00:00';
UPDATE "#__weblinks" SET "publish_down" = NULL WHERE "publish_down" = '1970-01-01 00:00:00';
UPDATE "#__weblinks" SET "checked_out_time" = NULL WHERE "checked_out_time" = '1970-01-01 00:00:00';
UPDATE "#__categories" SET "modified_time" = "created_time" WHERE "modified_time" = '1970-01-01 00:00:00' AND "extension" = 'com_weblinks';
UPDATE "#__categories" SET "checked_out_time" = NULL WHERE "checked_out_time" = '1970-01-01 00:00:00' AND "extension" = 'com_weblinks';
UPDATE "#__ucm_content" SET "core_modified_time" = "core_created_time"
WHERE "core_type_alias" IN ('com_weblinks.weblink', 'com_weblinks.category')
AND "core_modified_time" = '1970-01-01 00:00:00';
UPDATE "#__ucm_content" SET "core_publish_up" = NULL
WHERE "core_type_alias" = 'com_weblinks.weblink'
AND "core_publish_up" = '1970-01-01 00:00:00';
UPDATE "#__ucm_content" SET "core_publish_down" = NULL
WHERE "core_type_alias" = 'com_weblinks.weblink'
AND "core_publish_down" = '1970-01-01 00:00:00';
UPDATE "#__ucm_content" SET "core_checked_out_time" = NULL
WHERE "core_type_alias" IN ('com_weblinks.weblink', 'com_weblinks.category')
AND "core_checked_out_time" = '1970-01-01 00:00:00';

View File

@ -32,6 +32,14 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
{
use TaggableTableTrait;
/**
* 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
*
@ -66,9 +74,9 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
*
* @since 1.6
*/
public function store($updateNulls = false)
public function store($updateNulls = true)
{
$date = Factory::getDate();
$date = Factory::getDate()->toSql();
$user = Factory::getApplication()->getIdentity();
$this->modified = $date->toSql();
@ -77,6 +85,7 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
{
// Existing item
$this->modified_by = $user->id;
$this->modified = $date;
}
else
{
@ -84,7 +93,7 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
// so we don't touch either of these if they are set.
if (!(int) $this->created)
{
$this->created = $date->toSql();
$this->created = $date;
}
if (empty($this->created_by))
@ -92,22 +101,32 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
$this->created_by = $user->id;
}
if (!(int) $this->modified)
{
$this->modified = $date;
}
if (empty($this->modified_by))
{
$this->modified_by = $user->id;
}
if (empty($this->hits))
{
$this->hits = 0;
}
}
// Set publish_up to null date if not set
// Set publish_up to null if not set
if (!$this->publish_up)
{
$this->publish_up = $this->getDbo()->getNullDate();
$this->publish_up = null;
}
// Set publish_down to null date if not set
// Set publish_down to null if not set
if (!$this->publish_down)
{
$this->publish_down = $this->getDbo()->getNullDate();
$this->publish_down = null;
}
// Verify that the alias is unique
@ -187,7 +206,7 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
}
// Check the publish down date is not earlier than publish up.
if ($this->publish_down > $db->getNullDate() && $this->publish_down < $this->publish_up)
if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up)
{
$this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));