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

Enabled clearing caches directly from Jump Menu #4120

Open
wants to merge 1 commit into
base: 7.dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Enabled clearing caches directly from Jump Menu
  • Loading branch information
intoeetive committed Mar 6, 2024
commit ad5bfb2aa11ab8f23ed005d124dc921e3fe327ab
11 changes: 8 additions & 3 deletions system/ee/ExpressionEngine/Controller/Jumps/Caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

class Caches extends Jumps
{
private $themes = array('light' => 'fa-sun', 'dark' => 'fa-moon');

public function __construct()
{
parent::__construct();
if (!ee('Permission')->has('can_access_data')) {
$this->sendResponse([]);
}
}

/**
Expand Down Expand Up @@ -47,7 +48,11 @@ public function clear()
'command_title' => $command,
'dynamic' => false,
'addon' => false,
'target' => 'utilities/cache&cache_type=' . $key
'action' => true,
'target' => 'utilities/cache',
'data' => [
'cache_type' => $key
]
);
}

Expand Down
165 changes: 165 additions & 0 deletions system/ee/ExpressionEngine/Controller/Jumps/Utilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php
/**
* This source file is part of the open source project
* ExpressionEngine (https://expressionengine.com)
*
* @link https://expressionengine.com/
* @copyright Copyright (c) 2003-2023, Packet Tide, LLC (https://www.packettide.com)
* @license https://expressionengine.com/license Licensed under Apache License, Version 2.0
*/

namespace ExpressionEngine\Controller\Jumps;

use CP_Controller;

class Utilities extends Jumps
{
public function __construct()
{
parent::__construct();
if (!ee('Permission')->has('can_access_data')) {
$this->sendResponse([]);
}
}

/**
* Publish Jump Data
*/
public function index()
{
// Should never be here without another segment.
show_error(lang('unauthorized_access'), 403);
}

public function view()
{
$roles = $this->loadMemberRoles(ee()->input->post('searchString'));

$response = array();

foreach ($roles as $role) {
$response['viewMemberRole' . $role->name] = array(
'icon' => 'fa-eye',
'command' => $role->name,
'command_title' => $role->name,
'dynamic' => false,
'addon' => false,
'target' => ee('CP/URL')->make('members', array('role_id' => $role->getId()))->compile()
);
}

$this->sendResponse($response);
}

public function field()
{
$fields = $this->loadMemberFields(ee()->input->post('searchString'));

$response = array();

foreach ($fields as $field) {
$response['editMemberField' . $field->m_field_id] = array(
'icon' => 'fa-pencil-alt',
'command' => $field->m_field_label . ' ' . $field->m_field_name,
'command_title' => $field->m_field_name,
'dynamic' => false,
'addon' => false,
'target' => ee('CP/URL')->make('settings/member-fields/edit/' . $field->getId())->compile()
);
}

$this->sendResponse($response);
}

public function role()
{
$roles = $this->loadMemberRoles(ee()->input->post('searchString'));

$response = array();

foreach ($roles as $role) {
$response['editMemberRole' . $role->name] = array(
'icon' => 'fa-pencil-alt',
'command' => $role->name,
'command_title' => $role->name,
'dynamic' => false,
'addon' => false,
'target' => ee('CP/URL')->make('members/roles/edit/' . $role->getId())->compile()
);
}

$this->sendResponse($response);
}

public function edit()
{
$members = $this->loadMembers(ee()->input->post('searchString'));

$response = array();

foreach ($members as $member) {
$id = $member->getId();

$response['editMember' . $member->getId()] = array(
'icon' => 'fa-pencil-alt',
'command' => $member->username . ' ' . $member->email,
'command_title' => $member->username . ' <em>(' . $member->email . ')</em>',
'command_context' => $member->PrimaryRole->name,
'dynamic' => false,
'addon' => false,
'target' => ee('CP/URL')->make('members/profile/settings', array('id' => $member->getId()))->compile()
);
}

$this->sendResponse($response);
}

private function loadMemberFields($searchString = false)
{
$fields = ee('Model')->get('MemberField');

if (!empty($searchString)) {
// Break the search string into individual keywords so we can partially match them.
$keywords = explode(' ', $searchString);

foreach ($keywords as $keyword) {
$fields->filter('m_field_label', 'LIKE', '%' . ee()->db->escape_like_str($keyword) . '%');
}
}

return $fields->order('m_field_label', 'ASC')->limit(11)->all();
}

private function loadMemberRoles($searchString = false)
{
$roles = ee('Model')->get('Role');

if (!empty($searchString)) {
// Break the search string into individual keywords so we can partially match them.
$keywords = explode(' ', $searchString);

foreach ($keywords as $keyword) {
$roles->filter('name', 'LIKE', '%' . ee()->db->escape_like_str($keyword) . '%');
}
}

return $roles->order('name', 'ASC')->limit(11)->all();
}

private function loadMembers($searchString = false)
{
$members = ee('Model')->get('Member');

if (!empty($searchString)) {
// Break the search string into individual keywords so we can partially match them.
$keywords = explode(' ', $searchString);

foreach ($keywords as $keyword) {
$members->filter('username', 'LIKE', '%' . ee()->db->escape_like_str($keyword) . '%');
$members->orFilter('email', 'LIKE', '%' . ee()->db->escape_like_str($keyword) . '%');
}
}

return $members->order('username', 'ASC')->limit(11)->all();
}
}
38 changes: 32 additions & 6 deletions system/ee/ExpressionEngine/Controller/Utilities/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
/**
* Cache Manager
*
* @access public

Check failure on line 21 in system/ee/ExpressionEngine/Controller/Utilities/Cache.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed
* @return void

Check failure on line 22 in system/ee/ExpressionEngine/Controller/Utilities/Cache.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed
*/
public function index()
{
Expand Down Expand Up @@ -50,21 +50,47 @@
)
);

ee()->load->library('form_validation');
ee()->form_validation->set_rules('cache_type', 'lang:caches_to_clear', 'required|enum[all,page,tag,db]');
$validator = ee('Validation')->make();
$validator->setRules(array(
'cache_type' => 'required|enum[all,page,tag,db]',
));
$result = $validator->validate($_POST);
if ($response = $this->ajaxValidation($result)) {
return $response;
}

if (AJAX_REQUEST) {
ee()->form_validation->run_ajax();
exit;
} elseif (ee()->form_validation->run() !== false) {
if ($result->isValid()) {
ee()->functions->clear_caching(ee()->input->post('cache_type'));

if (ee()->input->post('cache_type') == 'all') {
ee('CP/JumpMenu')->clearAllCaches();
}

if (AJAX_REQUEST) {
// Jump menu request
ee()->output->send_ajax_response(array(
'success' => true,
'message' => lang('caches_cleared')
));
}

ee()->view->set_message('success', lang('caches_cleared'), '', true);
ee()->functions->redirect(ee('CP/URL')->make('utilities/cache'));
} else {
if (AJAX_REQUEST) {
// jump menu request
$validationErrors = [];
foreach ($result->getAllErrors() as $field => $errors) {
foreach ($errors as $error) {
$validationErrors[] = '<b>' . lang($field) . ':</b> ' . $error;
}
}
ee()->output->send_ajax_response(array(
'status' => 'error',
'error' => true,
'message' => implode('<br>', $validationErrors)
));
}
}

ee()->view->ajax_validate = true;
Expand Down
40 changes: 21 additions & 19 deletions system/ee/ExpressionEngine/Service/JumpMenu/JumpMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,22 @@
'target' => 'design',
'permission' => 'can_access_design'
),
//categories
'viewCategories' => array(
'icon' => 'fa-eye',
'command' => 'view edit_categories',
'dynamic' => false,
'addon' => false,
'target' => 'categories',
'permission' => 'can_edit_categories'
),
//cache
'systemUtilitiesCacheManager' => array(
'clearCaches' => array(
'icon' => 'fa-database',
'command' => 'system_utilities cache_manager caches_to_clear',
'dynamic' => false,
'command' => 'btn_clear_caches',
'dynamic' => true,
'addon' => false,
'target' => 'utilities/cache',
'target' => 'caches/clear',
'permission' => 'can_access_data'
),
//addons
Expand Down Expand Up @@ -203,14 +212,6 @@
'permission' => 'ban_users'
),
//categories
'viewCategories' => array(
'icon' => 'fa-eye',
'command' => 'view edit_categories',
'dynamic' => false,
'addon' => false,
'target' => 'categories',
'permission' => 'can_edit_categories'
),
'createCategoryIn' => array(
'icon' => 'fa-plus',
'command' => 'add_category',
Expand Down Expand Up @@ -1739,6 +1740,14 @@
'permission' => 'can_access_sys_prefs',
),
//utilities
'systemUtilitiesCacheManager' => array(
'icon' => 'fa-database',
'command' => 'system_utilities cache_manager caches_to_clear',
'dynamic' => false,
'addon' => false,
'target' => 'utilities/cache',
'permission' => 'can_access_data'
),
'systemUtilitiesCommunicate' => array(
'icon' => 'fa-hammer',
'command' => 'system_utilities communicate send_email',
Expand Down Expand Up @@ -1908,13 +1917,6 @@
'addon' => false,
'target' => 'homepage/toggle-viewmode'
),
/*'clearCaches' => array(
'icon' => 'fa-database',
'command' => 'btn_clear_caches',
'dynamic' => true,
'addon' => false,
'target' => 'caches/clear'
),*/
)
);

Expand Down Expand Up @@ -2112,13 +2114,13 @@
}

//check permissions for comment links
if (! ee('Permission')->hasAny(

Check failure on line 2117 in system/ee/ExpressionEngine/Service/JumpMenu/JumpMenu.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

The first expression of a multi-line control structure must be on the line after the opening parenthesis
'can_moderate_comments',
'can_edit_own_comments',
'can_delete_own_comments',
'can_edit_all_comments',
'can_delete_all_comments'
)) {

Check failure on line 2123 in system/ee/ExpressionEngine/Service/JumpMenu/JumpMenu.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Each line in a multi-line control structure must be indented at least once; expected at least 12 spaces, but found 8

Check failure on line 2123 in system/ee/ExpressionEngine/Service/JumpMenu/JumpMenu.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

The closing parenthesis of a multi-line control structure must be on the line after the last expression
unset($items[1]['viewComments']);
unset($items[1]['viewCommentsFor']);
}
Expand Down
Loading
Loading