Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further changes for pubish up and down null values #39

5 changes: 2 additions & 3 deletions components/com_content/Helper/AssociationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ public static function getAssociations($id = 0, $view = null, $layout = null)
if (!$user->authorise('core.edit.state', 'com_content') && !$user->authorise('core.edit', 'com_content'))
{
// Filter by start and end dates.
$nullDate = $db->quote($db->getNullDate());
$date = Factory::getDate();

$nowDate = $db->quote($date->toSql());

$advClause[] = '(c2.publish_up = ' . $nullDate . ' OR c2.publish_up <= ' . $nowDate . ')';
$advClause[] = '(c2.publish_down = ' . $nullDate . ' OR c2.publish_down >= ' . $nowDate . ')';
$advClause[] = '(c2.publish_up IS NULL OR c2.publish_up <= ' . $nowDate . ')';
$advClause[] = '(c2.publish_down IS NULL OR c2.publish_down >= ' . $nowDate . ')';

// Filter by published
$advClause[] = 'c2.state = 1';
Expand Down
4 changes: 2 additions & 2 deletions components/com_content/Helper/QueryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ public static function getQueryDate($orderDate, DatabaseInterface $db = null)

// Use created if publish_up is not set
case 'published' :
$queryDate = ' CASE WHEN a.publish_up = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.publish_up END ';
$queryDate = ' CASE WHEN a.publish_up IS NULL THEN a.created ELSE a.publish_up END ';
break;

case 'unpublished' :
$queryDate = ' CASE WHEN a.publish_down = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.publish_down END ';
$queryDate = ' CASE WHEN a.publish_down IS NULL THEN a.created ELSE a.publish_down END ';
break;
case 'created' :
default :
Expand Down
9 changes: 5 additions & 4 deletions components/com_content/Model/ArchiveModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,21 @@ protected function _getList($query, $limitstart=0, $limit=0)
public function getYears()
{
$db = $this->getDbo();
$nullDate = $db->quote($db->getNullDate());
$nowDate = $db->quote(Factory::getDate()->toSql());

$nowDate = $db->quote(Factory::getDate()->toSql());

$query = $db->getQuery(true);
$years = $query->year($db->quoteName('c.created'));

$query->select('DISTINCT (' . $years . ')')
->from($db->quoteName('#__content', 'c'))
->from($db->quoteName('#__workflow_associations', 'wa'))
->from($db->quoteName('#__workflow_stages', 'ws'))
->where($db->quoteName('c.id') . ' = ' . $db->quoteName('wa.item_id'))
->where($db->quoteName('ws.id') . ' = ' . $db->quoteName('wa.stage_id'))
->where($db->quoteName('ws.condition') . '= ' . (int) ContentComponent::CONDITION_ARCHIVED)
->where('(c.publish_up = ' . $nullDate . ' OR c.publish_up <= ' . $nowDate . ')')
->where('(c.publish_down = ' . $nullDate . ' OR c.publish_down >= ' . $nowDate . ')')
->where('(c.publish_up IS NULL OR c.publish_up <= ' . $nowDate . ')')
->where('(c.publish_down IS NULL OR c.publish_down >= ' . $nowDate . ')')
->order('1 ASC');

$db->setQuery($query);
Expand Down
5 changes: 2 additions & 3 deletions components/com_content/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,12 @@ public function getItem($pk = null)
)
{
// Filter by start and end dates.
$nullDate = $db->quote($db->getNullDate());
$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('(a.publish_up IS NULL OR a.publish_up <= ' . $nowDate . ')')
->where('(a.publish_down IS NULL OR a.publish_down >= ' . $nowDate . ')');
}

// Filter by published state.
Expand Down
14 changes: 7 additions & 7 deletions components/com_content/Model/ArticlesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected function getListQuery()
'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,' .
// Use created if publish_up is 0
'CASE WHEN a.publish_up = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.publish_up END as publish_up,' .
'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, ' .
'a.hits, a.featured, a.language, ' . $query->length('a.fulltext') . ' AS readmore, a.ordering'
)
Expand Down Expand Up @@ -473,8 +473,8 @@ function ($data) use ($db)
// Filter by start and end dates.
if ((!$user->authorise('core.edit.state', 'com_content')) && (!$user->authorise('core.edit', 'com_content')))
{
$query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')')
->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')');
$query->where('(a.publish_up IS NULL OR a.publish_up <= ' . $nowDate . ')')
->where('(a.publish_down IS NULL OR a.publish_down >= ' . $nowDate . ')');
}

// Filter by Date Range or Relative Date
Expand Down Expand Up @@ -530,13 +530,13 @@ function ($data) use ($db)
if ($monthFilter != '')
{
$query->where(
$db->quote(date("Y-m-d", strtotime($monthFilter)) . ' 00:00:00') . ' <= CASE WHEN a.publish_up = ' .
$db->quote($db->getNullDate()) . ' THEN a.created ELSE a.publish_up END'
$db->quote(date("Y-m-d", strtotime($monthFilter)) . ' 00:00:00')
. ' <= CASE WHEN a.publish_up IS NULL THEN a.created ELSE a.publish_up END'
);

$query->where(
$db->quote(date("Y-m-t", strtotime($monthFilter)) . ' 23:59:59') . ' >= CASE WHEN a.publish_up = ' .
$db->quote($db->getNullDate()) . ' THEN a.created ELSE a.publish_up END'
$db->quote(date("Y-m-t", strtotime($monthFilter)) . ' 23:59:59')
. ' >= CASE WHEN a.publish_up IS NULL THEN a.created ELSE a.publish_up END'
);
}
break;
Expand Down
2 changes: 1 addition & 1 deletion components/com_content/tmpl/article/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<?php if (strtotime($this->item->publish_up) > strtotime(Factory::getDate())) : ?>
<span class="badge badge-warning"><?php echo Text::_('JNOTPUBLISHEDYET'); ?></span>
<?php endif; ?>
<?php if ((strtotime($this->item->publish_down) < strtotime(Factory::getDate())) && $this->item->publish_down != Factory::getDbo()->getNullDate()) : ?>
<?php if (!is_null($this->item->publish_down) && (strtotime($this->item->publish_down) < strtotime(Factory::getDate()))) : ?>
<span class="badge badge-warning"><?php echo Text::_('JEXPIRED'); ?></span>
<?php endif; ?>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/com_content/tmpl/category/blog_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<div class="item-content">
<?php if ($this->item->stage_condition == ContentComponent::CONDITION_UNPUBLISHED || strtotime($this->item->publish_up) > strtotime(Factory::getDate())
|| ((strtotime($this->item->publish_down) < strtotime(Factory::getDate())) && $this->item->publish_down != Factory::getDbo()->getNullDate())) : ?>
|| (!is_null($this->item->publish_down) && strtotime($this->item->publish_down) < strtotime(Factory::getDate()))) : ?>
<div class="system-unpublished">
<?php endif; ?>

Expand Down Expand Up @@ -86,7 +86,7 @@
<?php endif; ?>

<?php if ($this->item->stage_condition == ContentComponent::CONDITION_UNPUBLISHED || strtotime($this->item->publish_up) > strtotime(Factory::getDate())
|| ((strtotime($this->item->publish_down) < strtotime(Factory::getDate())) && $this->item->publish_down != Factory::getDbo()->getNullDate())) : ?>
|| (!is_null($this->item->publish_down) && strtotime($this->item->publish_down) < strtotime(Factory::getDate()))) : ?>
</div>
<?php endif; ?>
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/com_content/tmpl/category/default_articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
<?php echo Text::_('JNOTPUBLISHEDYET'); ?>
</span>
<?php endif; ?>
<?php if ((strtotime($article->publish_down) < strtotime(Factory::getDate())) && $article->publish_down != Factory::getDbo()->getNullDate()) : ?>
<?php if (!is_null($article->publish_down) && strtotime($article->publish_down) < strtotime(Factory::getDate())) : ?>
<span class="list-published badge badge-warning">
<?php echo Text::_('JEXPIRED'); ?>
</span>
Expand Down
6 changes: 3 additions & 3 deletions components/com_content/tmpl/featured/default_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<div class="item-content">
<?php if ($this->item->state == Workflow::CONDITION_UNPUBLISHED || strtotime($this->item->publish_up) > strtotime(Factory::getDate())
|| ((strtotime($this->item->publish_down) < strtotime(Factory::getDate())) && $this->item->publish_down != Factory::getDbo()->getNullDate())) : ?>
|| (!is_null($this->item->publish_down) && strtotime($this->item->publish_down) < strtotime(Factory::getDate()))) : ?>
<div class="system-unpublished">
<?php endif; ?>

Expand All @@ -52,7 +52,7 @@
<?php if (strtotime($this->item->publish_up) > strtotime(Factory::getDate())) : ?>
<span class="badge badge-warning"><?php echo Text::_('JNOTPUBLISHEDYET'); ?></span>
<?php endif; ?>
<?php if ((strtotime($this->item->publish_down) < strtotime(Factory::getDate())) && $this->item->publish_down != Factory::getDbo()->getNullDate()) : ?>
<?php if (!is_null($this->item->publish_down) && strtotime($this->item->publish_down) < strtotime(Factory::getDate())) : ?>
<span class="badge badge-warning"><?php echo Text::_('JEXPIRED'); ?></span>
<?php endif; ?>

Expand Down Expand Up @@ -104,7 +104,7 @@
<?php endif; ?>

<?php if ($this->item->state == Workflow::CONDITION_UNPUBLISHED || strtotime($this->item->publish_up) > strtotime(Factory::getDate())
|| ((strtotime($this->item->publish_down) < strtotime(Factory::getDate())) && $this->item->publish_down != $this->db->getNullDate() )) : ?>
|| (!is_null($this->item->publish_down) && strtotime($this->item->publish_down) < strtotime(Factory::getDate()))) : ?>
</div>
<?php endif; ?>

Expand Down
6 changes: 2 additions & 4 deletions modules/mod_related_items/Helper/RelatedItemsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public static function getList(&$params)
$temp = explode(':', $temp);
$id = (int) $temp[0];

$nullDate = $db->getNullDate();
$now = Factory::getDate()->toSql();
$related = [];
$query = $db->getQuery(true);
Expand Down Expand Up @@ -131,16 +130,15 @@ public static function getList(&$params)
}

$query->extendWhere('AND', $wheres, 'OR')
->extendWhere('AND', [ $db->quoteName('a.publish_up') . ' = :nullDate1', $db->quoteName('a.publish_up') . ' <= :nowDate1'], 'OR')
->extendWhere('AND', [ $db->quoteName('a.publish_up') . ' IS NULL', $db->quoteName('a.publish_up') . ' <= :nowDate1'], 'OR')
->extendWhere(
'AND',
[
$db->quoteName('a.publish_down') . ' = :nullDate2',
$db->quoteName('a.publish_down') . ' IS NULL',
$db->quoteName('a.publish_down') . ' >= :nowDate2'
],
'OR'
)
->bind([':nullDate1', ':nullDate2'], $nullDate)
->bind([':nowDate1', ':nowDate2'], $now);

// Filter by language
Expand Down
6 changes: 3 additions & 3 deletions plugins/content/pagenavigation/pagenavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public function onContentBeforeDisplay($context, &$row, &$params, $page = 0)
}

$xwhere = ' AND (ws.condition = 1 OR ws.condition = -2)'
. ' AND (publish_up = ' . $db->quote($nullDate) . ' OR publish_up <= ' . $db->quote($now) . ')'
. ' AND (publish_down = ' . $db->quote($nullDate) . ' OR publish_down >= ' . $db->quote($now) . ')';
. ' AND (publish_up IS NULL OR publish_up <= ' . $db->quote($now) . ')'
. ' AND (publish_down IS NULL OR publish_down >= ' . $db->quote($now) . ')';

// Array of articles in same category correctly ordered.
$query = $db->getQuery(true);
Expand Down Expand Up @@ -258,7 +258,7 @@ private static function getQueryDate($orderDate)

// Use created if publish_up is not set
case 'published' :
$queryDate = ' CASE WHEN a.publish_up = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.publish_up END ';
$queryDate = ' CASE WHEN a.publish_up IS NULL THEN a.created ELSE a.publish_up END ';
break;

// Use created as default
Expand Down
2 changes: 1 addition & 1 deletion plugins/sampledata/multilang/multilang.php
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ private function addArticle($itemLanguage, $categoryId)
'created_by' => (int) $this->getAdminId(),
'created_by_alias' => 'Joomla',
'publish_up' => $currentDate,
'publish_down' => $db->getNullDate(),
'publish_down' => null,
'version' => 1,
'catid' => $categoryId,
'metadata' => '{"robots":"","author":"","rights":"","tags":null}',
Expand Down