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

[4.0] Menu items expiration #24416

Merged
merged 24 commits into from Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,2 @@
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';
@@ -0,0 +1,2 @@
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;
8 changes: 6 additions & 2 deletions administrator/components/com_menus/Model/ItemsModel.php
Expand Up @@ -56,6 +56,8 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu
'client_id', 'a.client_id',
'home', 'a.home',
'parent_id', 'a.parent_id',
'publish_up', 'a.publish_up',
'publish_down', 'a.publish_down',
'a.ordering'
);

Expand Down Expand Up @@ -260,12 +262,14 @@ protected function getListQuery()
array(
'a.id', 'a.menutype', 'a.title', 'a.alias', 'a.note', 'a.path', 'a.link', 'a.type', 'a.parent_id',
'a.level', 'a.published', 'a.component_id', 'a.checked_out', 'a.checked_out_time', 'a.browserNav',
'a.access', 'a.img', 'a.template_style_id', 'a.params', 'a.lft', 'a.rgt', 'a.home', 'a.language', 'a.client_id'
'a.access', 'a.img', 'a.template_style_id', 'a.params', 'a.lft', 'a.rgt', 'a.home', 'a.language',
'a.client_id', 'a.publish_up', 'a.publish_down'
),
array(
null, null, null, null, null, null, null, null, null,
null, 'a.published', null, null, null, null,
null, null, null, null, null, null, null, null, null
null, null, null, null, null, null, null, null,
null, 'publish_up', 'publish_down'
)
)
)
Expand Down
48 changes: 48 additions & 0 deletions administrator/components/com_menus/Table/MenuTable.php
Expand Up @@ -12,6 +12,7 @@
defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;

/**
* Menu table
Expand Down Expand Up @@ -47,4 +48,51 @@ public function delete($pk = null, $children = false)

return $return;
}

/**
* Overloaded check function
*
* @return boolean True on success, false on failure
*
* @see JTable::check
* @since __DEPLOY_VERSION__
*/
public function check()
{
$return = parent::check();

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

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

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

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

return false;
}

if ((int) $this->home)
{
// Set the publish down/up always for home.
$this->publish_up = $db->getNullDate();
$this->publish_down = $db->getNullDate();
}
}

return $return;
}
}
26 changes: 26 additions & 0 deletions administrator/components/com_menus/forms/item.xml
Expand Up @@ -77,6 +77,32 @@
<option value="-2">JTRASHED</option>
</field>

<field
name="publish_up"
type="calendar"
label="JGLOBAL_FIELD_PUBLISH_UP_LABEL"
id="publish_up"
class="inputbox"
translateformat="true"
showtime="true"
size="22"
filter="user_utc"
showon="home:0"
/>

<field
name="publish_down"
type="calendar"
label="JGLOBAL_FIELD_PUBLISH_DOWN_LABEL"
id="publish_down"
class="inputbox"
translateformat="true"
showtime="true"
size="22"
filter="user_utc"
showon="home:0"
/>

<field
name="parent_id"
type="MenuParent"
Expand Down
4 changes: 4 additions & 0 deletions administrator/components/com_menus/tmpl/item/edit.php
Expand Up @@ -141,6 +141,8 @@
'parent_id',
'menuordering',
'published',
'publish_up',
'publish_down',
'home',
'access',
'language',
Expand All @@ -150,6 +152,8 @@
if ($this->item->type != 'component')
{
$this->fields = array_diff($this->fields, array('home'));
$this->form->setFieldAttribute('publish_up', 'showon', '');
$this->form->setFieldAttribute('publish_down', 'showon', '');
}

echo LayoutHelper::render('joomla.edit.global', $this); ?>
Expand Down
5 changes: 1 addition & 4 deletions administrator/components/com_menus/tmpl/items/default.php
Expand Up @@ -170,10 +170,7 @@
<?php echo HTMLHelper::_('grid.id', $i, $item->id); ?>
</td>
<td class="text-center">
<?php
// Show protected items as published always. We don't allow state change for them. Show/Hide is the module's job.
$published = $item->protected ? 3 : $item->published;
echo HTMLHelper::_('menus.state', $published, $i, $canChange && !$item->protected, 'cb'); ?>
<?php echo HTMLHelper::_('jgrid.published', $item->published, $i, 'items.', $canChange, 'cb', $item->publish_up, $item->publish_down); ?>
</td>
<th scope="row">
<?php $prefix = LayoutHelper::render('joomla.html.treeprefix', array('level' => $item->level)); ?>
Expand Down
2 changes: 2 additions & 0 deletions installation/sql/mysql/joomla.sql
Expand Up @@ -1288,6 +1288,8 @@ CREATE TABLE IF NOT EXISTS `#__menu` (
`home` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT 'Indicates if this menu item is the home or default page.',
`language` char(7) NOT NULL DEFAULT '',
`client_id` tinyint(4) NOT NULL DEFAULT 0,
`publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
UNIQUE KEY `idx_client_id_parent_id_alias_language` (`client_id`,`parent_id`,`alias`(100),`language`),
KEY `idx_componentid` (`component_id`,`menutype`,`published`,`access`),
Expand Down
2 changes: 2 additions & 0 deletions installation/sql/postgresql/joomla.sql
Expand Up @@ -1272,6 +1272,8 @@ CREATE TABLE IF NOT EXISTS "#__menu" (
"home" smallint DEFAULT 0 NOT NULL,
"language" varchar(7) DEFAULT '' NOT NULL,
"client_id" smallint DEFAULT 0 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,
PRIMARY KEY ("id"),
CONSTRAINT "#__menu_idx_client_id_parent_id_alias_language" UNIQUE ("client_id", "parent_id", "alias", "language")
);
Expand Down
4 changes: 4 additions & 0 deletions libraries/src/Menu/SiteMenu.php
Expand Up @@ -80,6 +80,8 @@ public function load()
{
$loader = function ()
{
$nulldate = $this->db->quote($this->db->getNullDate());
$currentDate = Factory::getDate()->toSql();
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding $this->db->quote() here and removing it from below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all the query should be "quoted", i'll do it if this pr will land in core

$query = $this->db->getQuery(true)
->select('m.id, m.menutype, m.title, m.alias, m.note, m.path AS route, m.link, m.type, m.level, m.language')
->select($this->db->quoteName('m.browserNav') . ', m.access, m.params, m.home, m.img, m.template_style_id, m.component_id, m.parent_id')
Expand All @@ -89,6 +91,8 @@ public function load()
->where('m.published = 1')
->where('m.parent_id > 0')
->where('m.client_id = 0')
->where('(m.publish_up = ' . $nulldate . ' OR m.publish_up <= ' . $this->db->quote($currentDate) . ')')
->where('(m.publish_down = ' . $nulldate . ' OR m.publish_down >= ' . $this->db->quote($currentDate) . ')')
->order('m.lft');

// Set the query
Expand Down