Skip to content

Commit

Permalink
Merge pull request concretecms#12373 from aembler/misc-fixes-94x-121124
Browse files Browse the repository at this point in the history
  • Loading branch information
aembler authored Dec 12, 2024
2 parents f5d8563 + 553b27b commit 09798f7
Show file tree
Hide file tree
Showing 12 changed files with 470 additions and 150 deletions.
133 changes: 62 additions & 71 deletions concrete/controllers/dialog/page/bulk/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,30 @@

use Concrete\Controller\Backend\UserInterface as BackendInterfaceController;
use Concrete\Core\Application\EditResponse;
use Concrete\Core\Command\Batch\Batch;
use Concrete\Core\Page\Command\DeletePageCommand;
use Page;
use Concrete\Core\Controller\Traits\DashboardBulkUpdaterTrait;
use Concrete\Core\Page\Page;
use Concrete\Core\Permission\Checker;
use Permissions;
use Symfony\Component\HttpFoundation\JsonResponse;

class Cache extends BackendInterfaceController
{
use DashboardBulkUpdaterTrait;
protected $viewPath = '/dialogs/page/bulk/cache';
protected $pages;
protected $canEdit = false;

protected function canAccess()
protected function getObjectFromRequestId(string $id)
{
$this->populatePages();

return $this->canEdit;
$page = Page::getByID($id, 'RECENT');
if ($page && !$page->isError()) {
return $page;
}
return null;
}

protected function populatePages()
public function canPerformOperationOnObject($object): bool
{
if (!isset($this->pages)) {
if (is_array($_REQUEST['item'])) {
foreach ($_REQUEST['item'] as $cID) {
$c = Page::getByID($cID);
if (is_object($c) && !$c->isError()) {
$this->pages[] = $c;
}
}
}
}

if (count($this->pages) > 0) {
$this->canEdit = true;
foreach ($this->pages as $c) {
$cp = new Permissions($c);
if (!$cp->canEditPageSpeedSettings()) {
$this->canEdit = false;
}
}
} else {
$this->canEdit = false;
}

return $this->canEdit;
$checker = new Checker($object);
return $checker->canEditPageSpeedSettings();
}

public function view()
Expand All @@ -57,7 +36,7 @@ public function view()
$fullPageCaching = -3;
$cCacheFullPageContentOverrideLifetime = -2;
$cCacheFullPageContentOverrideLifetimeCustomValue = -1;
foreach ($this->pages as $c) {
foreach ($this->items as $c) {
$cp = new Permissions($c);
if ($cp->canEditPageSpeedSettings()) {
if ($c->getCollectionFullPageCaching() != $fullPageCaching && $fullPageCaching != -3) {
Expand All @@ -75,40 +54,48 @@ public function view()
) != $cCacheFullPageContentOverrideLifetimeCustomValue && $cCacheFullPageContentOverrideLifetimeCustomValue != -1) {
$cCacheFullPageContentOverrideLifetimeCustomValue = 0;
} else {
$cCacheFullPageContentOverrideLifetimeCustomValue = $c->getCollectionFullPageCachingLifetimeCustomValue();
$cCacheFullPageContentOverrideLifetimeCustomValue = $c->getCollectionFullPageCachingLifetimeCustomValue(
);
}
}
}
switch($config->get('concrete.cache.pages')) {
case 'blocks':
$globalSetting = t('cache page if all blocks support it.');
$enableCache = 1;
break;
case 'all':
$globalSetting = t('enable full page cache.');
$enableCache = 1;
break;
switch ($config->get('concrete.cache.pages')) {
case 'blocks':
$globalSetting = t('cache page if all blocks support it.');
$enableCache = 1;
break;
case 'all':
$globalSetting = t('enable full page cache.');
$enableCache = 1;
break;
default: // false
$globalSetting = t('disable full page cache.');
$enableCache = 0;
break;
}
switch($this->app->make('config')->get('concrete.cache.full_page_lifetime')) {
case 'custom':
$custom = $this->app->make('date')->describeInterval($config->get('concrete.cache.full_page_lifetime_value') * 60);
$globalSettingLifetime = t('%s minutes', $custom);
break;
case 'forever':
$globalSettingLifetime = t('Until manually cleared');
break;
$globalSetting = t('disable full page cache.');
$enableCache = 0;
break;
}
switch ($this->app->make('config')->get('concrete.cache.full_page_lifetime')) {
case 'custom':
$custom = $this->app->make('date')->describeInterval(
$config->get('concrete.cache.full_page_lifetime_value') * 60
);
$globalSettingLifetime = t('%s minutes', $custom);
break;
case 'forever':
$globalSettingLifetime = t('Until manually cleared');
break;
default: // "default"
$globalSettingLifetime = $this->app->make('date')->describeInterval($config->get('concrete.cache.lifetime'));
break;
}
$this->set('pages', $this->pages);
$globalSettingLifetime = $this->app->make('date')->describeInterval(
$config->get('concrete.cache.lifetime')
);
break;
}
$this->set('pages', $this->items);
$this->set('fullPageCaching', $fullPageCaching);
$this->set('cCacheFullPageContentOverrideLifetime', $cCacheFullPageContentOverrideLifetime);
$this->set('cCacheFullPageContentOverrideLifetimeCustomValue', $cCacheFullPageContentOverrideLifetimeCustomValue);
$this->set(
'cCacheFullPageContentOverrideLifetimeCustomValue',
$cCacheFullPageContentOverrideLifetimeCustomValue
);
$this->set('globalSetting', $globalSetting);
$this->set('enableCache', $enableCache);
$this->set('globalSettingLifetime', $globalSettingLifetime);
Expand All @@ -117,17 +104,21 @@ public function view()
public function submit()
{
if ($this->canAccess()) {
foreach ($this->pages as $page) {
$data = array();
if (($cCacheFullPageContent = $this->request->request->getInt('cCacheFullPageContent')) > -2) {
$data['cCacheFullPageContent'] = $cCacheFullPageContent;
}
if ($cCacheFullPageContent === 1) {
$data['cCacheFullPageContentOverrideLifetime'] = $this->request->request->get('cCacheFullPageContentOverrideLifetime');
foreach ($this->items as $page) {
$data = array();
if (($cCacheFullPageContent = $this->request->request->getInt('cCacheFullPageContent')) > -2) {
$data['cCacheFullPageContent'] = $cCacheFullPageContent;
}
if ($cCacheFullPageContent === 1) {
$data['cCacheFullPageContentOverrideLifetime'] = $this->request->request->get(
'cCacheFullPageContentOverrideLifetime'
);
if ($data['cCacheFullPageContentOverrideLifetime'] === 'custom') {
$data['cCacheFullPageContentLifetimeCustom'] = $this->request->request->getInt('cCacheFullPageContentLifetimeCustom');
$data['cCacheFullPageContentLifetimeCustom'] = $this->request->request->getInt(
'cCacheFullPageContentLifetimeCustom'
);
}
}
}
if (count($data) > 0) {
$page->update($data);
}
Expand Down
52 changes: 16 additions & 36 deletions concrete/controllers/dialog/page/bulk/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,45 @@

use Concrete\Controller\Backend\UserInterface as BackendInterfaceController;
use Concrete\Core\Command\Batch\Batch;
use Concrete\Core\Controller\Traits\DashboardBulkUpdaterTrait;
use Concrete\Core\Page\Command\DeletePageCommand;
use Page;
use Permissions;
use Concrete\Core\Page\Page;
use Concrete\Core\Permission\Checker;

class Delete extends BackendInterfaceController
{
use DashboardBulkUpdaterTrait;
protected $viewPath = '/dialogs/page/bulk/delete';
protected $pages;
protected $canEdit = false;

protected function canAccess()
protected function getObjectFromRequestId(string $id)
{
$this->populatePages();

return $this->canEdit;
$page = Page::getByID($id, 'RECENT');
if ($page && !$page->isError()) {
return $page;
}
return null;
}

protected function populatePages()
public function canPerformOperationOnObject($object): bool
{
if (!isset($this->pages)) {
if (is_array($_REQUEST['item'])) {
foreach ($_REQUEST['item'] as $cID) {
$c = Page::getByID($cID);
if (is_object($c) && !$c->isError()) {
$this->pages[] = $c;
}
}
}
}

if (count($this->pages) > 0) {
$this->canEdit = true;
foreach ($this->pages as $c) {
$cp = new Permissions($c);
if (!$cp->canDeletePage()) {
$this->canEdit = false;
}
}
} else {
$this->canEdit = false;
}

return $this->canEdit;
$checker = new Checker($object);
return $checker->canDeletePage();
}

public function view()
{
$this->populatePages();
$this->populateItemsFromRequest();
$this->set('form', $this->app->make('helper/form'));
$this->set('dh', $this->app->make('helper/date'));
$this->set('pages', $this->pages);
$this->set('pages', $this->items);
}

public function submit()
{
if ($this->canAccess()) {
$u = new \User();
$uID = $u->getUserID();
$pages = $this->pages;
$pages = $this->items;
$batch = Batch::create(t('Delete Pages'), function() use ($uID, $pages) {
foreach ($pages as $page) {
yield new DeletePageCommand($page->getCollectionID(), $uID);
Expand Down
Loading

0 comments on commit 09798f7

Please sign in to comment.