Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE `#__ucm_content` MODIFY `core_created_time` datetime NOT NULL;
ALTER TABLE `#__ucm_content` MODIFY `core_modified_time` datetime NOT NULL;

ALTER TABLE `#__ucm_content` MODIFY `core_publish_up` datetime NULL DEFAULT NULL;
ALTER TABLE `#__ucm_content` MODIFY `core_publish_down` datetime NULL DEFAULT NULL;
ALTER TABLE `#__ucm_content` MODIFY `core_checked_out_time` datetime NULL DEFAULT NULL;

ALTER TABLE `#__ucm_history` MODIFY `save_date` datetime NOT NULL;
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
ALTER TABLE `#__content` MODIFY `created` datetime NOT NULL;
ALTER TABLE `#__content` MODIFY `modified` datetime NOT NULL;

ALTER TABLE `#__content` MODIFY `publish_up` datetime NULL DEFAULT NULL;
ALTER TABLE `#__content` MODIFY `publish_down` datetime NULL DEFAULT NULL;
ALTER TABLE `#__content` MODIFY `checked_out_time` datetime NULL DEFAULT NULL;

UPDATE `#__content` SET `modified` = `created` WHERE `modified` = '0000-00-00 00:00:00';

UPDATE `#__content` SET `publish_up` = NULL WHERE `publish_up` = '0000-00-00 00:00:00';
UPDATE `#__content` SET `publish_down` = NULL WHERE `publish_down` = '0000-00-00 00:00:00';
UPDATE `#__content` SET `checked_out_time` = NULL WHERE `checked_out_time` = '0000-00-00 00:00:00';

UPDATE `#__ucm_content` SET `core_modified_time` = `core_created_time`
WHERE `core_type_alias` = 'com_content.article'
AND `core_modified_time` = '0000-00-00 00:00:00';

UPDATE `#__ucm_content` SET `core_publish_up` = NULL
WHERE `core_type_alias` = 'com_content.article'
AND `core_publish_up` = '0000-00-00 00:00:00';
UPDATE `#__ucm_content` SET `core_publish_down` = NULL
WHERE `core_type_alias` = 'com_content.article'
AND `core_publish_down` = '0000-00-00 00:00:00';
UPDATE `#__ucm_content` SET `core_checked_out_time` = NULL
WHERE `core_type_alias` = 'com_content.article'
AND `core_checked_out_time` = '0000-00-00 00:00:00';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALTER TABLE "#__ucm_content" ALTER COLUMN "core_created_time" DROP DEFAULT;

ALTER TABLE "#__ucm_content" ALTER COLUMN "core_modified_time" DROP DEFAULT;

ALTER TABLE "#__ucm_content" ALTER COLUMN "core_publish_up" DROP NOT NULL;
ALTER TABLE "#__ucm_content" ALTER COLUMN "core_publish_up" DROP DEFAULT;

ALTER TABLE "#__ucm_content" ALTER COLUMN "core_publish_down" DROP NOT NULL;
ALTER TABLE "#__ucm_content" ALTER COLUMN "core_publish_down" DROP DEFAULT;

ALTER TABLE "#__ucm_content" ALTER COLUMN "core_checked_out_time" DROP NOT NULL;
ALTER TABLE "#__ucm_content" ALTER COLUMN "core_checked_out_time" DROP DEFAULT;

ALTER TABLE "#__ucm_history" ALTER COLUMN "save_date" DROP DEFAULT;
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
ALTER TABLE "#__content" ALTER COLUMN "created" DROP DEFAULT;

ALTER TABLE "#__content" ALTER COLUMN "modified" DROP DEFAULT;

ALTER TABLE "#__content" ALTER COLUMN "publish_up" DROP NOT NULL;
ALTER TABLE "#__content" ALTER COLUMN "publish_up" DROP DEFAULT;

Expand All @@ -10,3 +14,13 @@ ALTER TABLE "#__content" ALTER COLUMN "checked_out_time" DROP DEFAULT;
UPDATE "#__content" SET "publish_up" = NULL WHERE "publish_up" = '1970-01-01 00:00:00';
UPDATE "#__content" SET "publish_down" = NULL WHERE "publish_down" = '1970-01-01 00:00:00';
UPDATE "#__content" SET "checked_out_time" = NULL WHERE "checked_out_time" = '1970-01-01 00:00:00';

UPDATE "#__ucm_content" SET "core_publish_up" = NULL
WHERE "core_type_alias" = 'com_content.article'
AND "core_publish_up" = '1970-01-01 00:00:00';
UPDATE "#__ucm_content" SET "core_publish_down" = NULL
WHERE "core_type_alias" = 'com_content.article'
AND "core_publish_down" = '1970-01-01 00:00:00';
UPDATE "#__ucm_content" SET "core_checked_out_time" = NULL
WHERE "core_type_alias" = 'com_content.article'
AND "core_checked_out_time" = '1970-01-01 00:00:00';
4 changes: 1 addition & 3 deletions components/com_content/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ public function getItem($pk = null)
$this->getState(
'item.select', 'a.id, a.asset_id, a.title, a.alias, a.introtext, a.fulltext, ' .
'a.state, a.catid, a.created, a.created_by, a.created_by_alias, ' .
// Use created if modified is 0
'CASE WHEN a.modified = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.modified END as modified, ' .
'a.modified_by, a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, ' .
'a.modified, a.modified_by, a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, ' .
'a.images, a.urls, a.attribs, a.version, a.ordering, ' .
'a.metakey, a.metadesc, a.access, a.hits, a.metadata, a.featured, a.language'
)
Expand Down
9 changes: 3 additions & 6 deletions components/com_content/Model/ArticlesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ protected function getListQuery()
// If category is not published then force 0
'CASE WHEN c.published = 2 AND ws.condition > 0 THEN ' . (int) ContentComponent::CONDITION_ARCHIVED .
' WHEN c.published != 1 THEN ' . (int) ContentComponent::CONDITION_UNPUBLISHED . ' ELSE ws.condition END as state,' .
// Use created if modified is 0
'CASE WHEN a.modified = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.modified END as modified, ' .
'a.modified_by, uam.name as modified_by_name,' .
'a.modified, a.modified_by, uam.name as modified_by_name,' .
// Use created if publish_up is 0
'CASE WHEN a.publish_up IS NULL THEN a.created ELSE a.publish_up END as publish_up,' .
'a.publish_down, a.images, a.urls, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, ' .
Expand Down Expand Up @@ -467,7 +465,6 @@ function ($data) use ($db)
}

// Define null and now dates
$nullDate = $db->quote($db->getNullDate());
$nowDate = $db->quote(Factory::getDate()->toSql());

// Filter by start and end dates.
Expand All @@ -484,8 +481,8 @@ function ($data) use ($db)
switch ($dateFiltering)
{
case 'range':
$startDateRange = $db->quote($this->getState('filter.start_date_range', $nullDate));
$endDateRange = $db->quote($this->getState('filter.end_date_range', $nullDate));
$startDateRange = $db->quote($this->getState('filter.start_date_range'));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wilsonge Here and in the following line you have to advise me if that is ok or if there has to be something done for one of the range start and end dates being not specified, or both even. The existing code might do the wrong thing in such case, if that case is allowed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the options for this? We've effectively mandated a.created and a.modified

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, these here are start and end dates for a range filtering, i think. they are entered in a filter. the date to be fitered for is either created or modified, but my question above refers to that start and end dates of the range for filtering. or am i getting something wrong?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok can be a.publish_up (mod_articles_popular and mod_articles_category). Just need to test this still works

$endDateRange = $db->quote($this->getState('filter.end_date_range'));
$query->where(
'(' . $dateField . ' >= ' . $startDateRange . ' AND ' . $dateField .
' <= ' . $endDateRange . ')'
Expand Down
16 changes: 8 additions & 8 deletions installation/sql/mysql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ CREATE TABLE IF NOT EXISTS `#__content` (
`fulltext` mediumtext NOT NULL,
`state` tinyint(3) NOT NULL DEFAULT 0,
`catid` int(10) unsigned NOT NULL DEFAULT 0,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL,
`created_by` int(10) 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(10) unsigned NOT NULL DEFAULT 0,
`checked_out` int(10) unsigned NOT NULL DEFAULT 0,
`checked_out_time` datetime NULL DEFAULT NULL,
Expand Down Expand Up @@ -1863,20 +1863,20 @@ CREATE TABLE IF NOT EXISTS `#__ucm_content` (
`core_alias` varchar(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`core_body` mediumtext NOT NULL DEFAULT '',
`core_state` tinyint(1) NOT NULL DEFAULT 0,
`core_checked_out_time` varchar(255) NOT NULL DEFAULT '0000-00-00 00:00:00',
`core_checked_out_time` datetime,
`core_checked_out_user_id` int(10) unsigned NOT NULL DEFAULT 0,
`core_access` int(10) unsigned NOT NULL DEFAULT 0,
`core_params` text NOT NULL DEFAULT '',
`core_featured` tinyint(4) unsigned NOT NULL DEFAULT 0,
`core_metadata` varchar(2048) NOT NULL DEFAULT '' COMMENT 'JSON encoded metadata properties.',
`core_created_user_id` int(10) unsigned NOT NULL DEFAULT 0,
`core_created_by_alias` varchar(255) NOT NULL DEFAULT '',
`core_created_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`core_created_time` datetime NOT NULL,
`core_modified_user_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Most recent user that modified',
`core_modified_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`core_modified_time` datetime NOT NULL,
`core_language` char(7) NOT NULL DEFAULT '',
`core_publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`core_publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`core_publish_up` datetime,
`core_publish_down` datetime,
`core_content_item_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'ID from the individual type table',
`asset_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'FK to the #__assets table.',
`core_images` text NOT NULL DEFAULT '',
Expand Down Expand Up @@ -1914,7 +1914,7 @@ CREATE TABLE IF NOT EXISTS `#__ucm_history` (
`ucm_item_id` int(10) unsigned NOT NULL,
`ucm_type_id` int(10) unsigned NOT NULL,
`version_note` varchar(255) NOT NULL DEFAULT '' COMMENT 'Optional version name',
`save_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`save_date` datetime NOT NULL,
`editor_user_id` int(10) unsigned NOT NULL DEFAULT 0,
`character_count` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Number of characters in this version.',
`sha1_hash` varchar(50) NOT NULL DEFAULT '' COMMENT 'SHA1 hash of the version_data column.',
Expand Down
16 changes: 8 additions & 8 deletions installation/sql/postgresql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ CREATE TABLE IF NOT EXISTS "#__content" (
"fulltext" text NOT NULL,
"state" smallint DEFAULT 0 NOT NULL,
"catid" bigint DEFAULT 0 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" bigint 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" bigint DEFAULT 0 NOT NULL,
"checked_out" bigint DEFAULT 0 NOT NULL,
"checked_out_time" timestamp without time zone,
Expand Down Expand Up @@ -1855,20 +1855,20 @@ CREATE TABLE IF NOT EXISTS "#__ucm_content" (
"core_alias" varchar(255) DEFAULT '' NOT NULL,
"core_body" text NOT NULL DEFAULT '',
"core_state" smallint DEFAULT 0 NOT NULL,
"core_checked_out_time" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"core_checked_out_time" timestamp without time zone,
"core_checked_out_user_id" bigint DEFAULT 0 NOT NULL,
"core_access" bigint DEFAULT 0 NOT NULL,
"core_params" text DEFAULT '' NOT NULL,
"core_featured" smallint DEFAULT 0 NOT NULL,
"core_metadata" text DEFAULT '' NOT NULL,
"core_created_user_id" bigint DEFAULT 0 NOT NULL,
"core_created_by_alias" varchar(255) DEFAULT '' NOT NULL,
"core_created_time" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"core_created_time" timestamp without time zone NOT NULL,
"core_modified_user_id" bigint DEFAULT 0 NOT NULL,
"core_modified_time" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"core_modified_time" timestamp without time zone NOT NULL,
"core_language" varchar(7) DEFAULT '' NOT NULL,
"core_publish_up" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"core_publish_down" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"core_publish_up" timestamp without time zone,
"core_publish_down" timestamp without time zone,
"core_content_item_id" bigint DEFAULT 0 NOT NULL,
"asset_id" bigint DEFAULT 0 NOT NULL,
"core_images" text DEFAULT '' NOT NULL,
Expand Down Expand Up @@ -1905,7 +1905,7 @@ CREATE TABLE IF NOT EXISTS "#__ucm_history" (
"ucm_item_id" integer NOT NULL,
"ucm_type_id" integer NOT NULL,
"version_note" varchar(255) NOT NULL DEFAULT '',
"save_date" timestamp with time zone NOT NULL DEFAULT '1970-01-01 00:00:00',
"save_date" timestamp with time zone NOT NULL,
"editor_user_id" integer NOT NULL DEFAULT 0,
"character_count" integer NOT NULL DEFAULT 0,
"sha1_hash" varchar(50) NOT NULL DEFAULT '',
Expand Down
17 changes: 15 additions & 2 deletions libraries/src/Table/CoreContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
*/
class CoreContent extends Table
{
/**
* Indicates that columns fully support the NULL value in the database
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $_supportNullValue = true;

/**
* Constructor
*
Expand Down Expand Up @@ -245,7 +253,7 @@ public function deleteByContentId($contentItemId = null, $typeAlias = null)
*
* @since 3.1
*/
public function store($updateNulls = false)
public function store($updateNulls = true)
{
$date = Factory::getDate();
$user = Factory::getUser();
Expand All @@ -271,6 +279,11 @@ public function store($updateNulls = false)
$this->core_created_user_id = $user->get('id');
}

if (!(int) $this->core_modified_time)
{
$this->core_modified_time = $this->core_created_time;
}

$isNew = true;
}

Expand All @@ -296,7 +309,7 @@ public function store($updateNulls = false)
*
* @since 3.1
*/
protected function storeUcmBase($updateNulls = false, $isNew = false)
protected function storeUcmBase($updateNulls = true, $isNew = false)
{
// Store the ucm_base row
$db = $this->getDbo();
Expand Down
3 changes: 1 addition & 2 deletions plugins/content/pagenavigation/pagenavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function onContentBeforeDisplay($context, &$row, &$params, $page = 0)
$db = Factory::getDbo();
$user = Factory::getUser();
$lang = Factory::getLanguage();
$nullDate = $db->getNullDate();

$date = Factory::getDate();
$now = $date->toSql();
Expand Down Expand Up @@ -253,7 +252,7 @@ private static function getQueryDate($orderDate)
{
// Use created if modified is not set
case 'modified' :
$queryDate = ' CASE WHEN a.modified = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.modified END';
$queryDate = ' a.modified';
break;

// Use created if publish_up is not set
Expand Down