Skip to content
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
7 changes: 6 additions & 1 deletion _build/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"lowCaseName": "fred",
"description": "Frontend Editor",
"author": "John Peca",
"version": "3.1.6-pl",
"version": "3.2.0-pl",
"package": {
"menus": [
{
Expand Down Expand Up @@ -99,6 +99,11 @@
{
"key": "lit",
"value": "0"
},
{
"key": "batch_size",
"value": "10",
"type": "numberfield"
}
]
},
Expand Down
7 changes: 6 additions & 1 deletion _build/gpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"lowCaseName": "fred",
"description": "Frontend Editor",
"author": "John Peca",
"version": "3.1.6-pl",
"version": "3.2.0-pl",
"menus": [
{
"text": "fred.menu.fred",
Expand Down Expand Up @@ -95,6 +95,11 @@
{
"key": "lit",
"value": "0"
},
{
"key": "batch_size",
"value": "10",
"type": "numberfield"
}
],
"database": {
Expand Down
79 changes: 72 additions & 7 deletions assets/components/fred/mgr/js/home/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,35 +228,100 @@ Ext.extend(fred.panel.Home, MODx.Panel, {
{
html: '<p>' + _('fred.rebuild.rebuild_desc') + '</p><br>'
},
{
xtype: 'fred-combo-themes',
id: 'fred-rebuild-theme',
fieldLabel: _('fred.rebuild.theme'),
isUpdate: true,
addAll: 1,
width: 300,
allowBlank: true
},
{
xtype: 'button',
text: _('fred.rebuild.rebuild'),
style: 'margin-top: 10px',
handler: function() {
var topic = '/fred/mgr/generate/refresh/';
var batchSize = MODx.config['fred.batch_size'] || 10;
var offset = 0;
var total = 0;
var themeCombo = Ext.getCmp('fred-rebuild-theme');
var theme = themeCombo ? (themeCombo.getValue() || 0) : 0;

var console = MODx.load({
var consoleWin = MODx.load({
xtype: 'modx-console',
register: 'mgr',
topic: topic,
show_filename: 0
});

console.show(Ext.getBody());
consoleWin.show(Ext.getBody());

function processNextBatch() {
var isLast = (offset + batchSize) >= total;
MODx.Ajax.request({
url: fred.config.connectorUrl,
params: {
action: 'Fred\\Processors\\Generate\\Refresh',
register: 'mgr',
topic: topic,
offset: offset,
limit: batchSize,
isLast: isLast ? 1 : 0,
theme: theme
},
listeners: {
success: {
fn: function() {
offset += batchSize;
if (offset < total) {
processNextBatch();
} else {
consoleWin.fireEvent('complete');
consoleWin = null;
}
},
scope: this
},
failure: {
fn: function() {
consoleWin.fireEvent('complete');
consoleWin = null;
},
scope: this
}
}
});
}

MODx.Ajax.request({
url: fred.config.connectorUrl,
params: {
action: 'Fred\\Processors\\Generate\\Refresh',
action: 'Fred\\Processors\\Generate\\Count',
register: 'mgr',
topic: topic
topic: topic,
theme: theme
},
listeners: {
success: {
fn: function(r) {
total = r.object.total;
if (total === 0) {
consoleWin.fireEvent('complete');
consoleWin = null;
return;
}
processNextBatch();
},
scope: this
},
failure: {
fn: function() {
console.fireEvent('complete');
console = null
consoleWin.fireEvent('complete');
consoleWin = null;
},
scope:this
scope: this
}
}
});
Expand Down
3 changes: 3 additions & 0 deletions core/components/fred/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@

$_lang['fred.rebuild.rebuild'] = 'Rebuild';
$_lang['fred.rebuild.rebuild_desc'] = 'Click the Rebuild button below to publish the changes in updated Elements to all existing Fred-powerd site pages.';
$_lang['fred.rebuild.theme'] = 'Theme';

$_lang['fred.element_cateogries.all'] = 'All Categories';
$_lang['fred.element_categories.none'] = 'No Categories were found.';
Expand Down Expand Up @@ -272,6 +273,8 @@
$_lang['setting_fred.force_sidebar_desc'] = 'When enabled, user won\'t be able to close the sidebar.';
$_lang['setting_fred.logout_url'] = 'Logout Link';
$_lang['setting_fred.logout_url_desc'] = 'Custom logout link. If filled, users will redirect there instead of to the manager logout after clicking the logout button.';
$_lang['setting_fred.batch_size'] = 'Regenerate Batch Size';
$_lang['setting_fred.batch_size_desc'] = 'Maximum number of resources to process in a single batch when regenerating (set to lower values to increase performance).';

$_lang['fred.err.blueprint_categories_ns_name'] = 'Name is required';
$_lang['fred.err.blueprints_ns_name'] = 'Name is required';
Expand Down
5 changes: 5 additions & 0 deletions core/components/fred/processors/mgr/generate/count.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

require_once(dirname(__FILE__, 4) . '/vendor/autoload.php');

return \Fred\v2\Processors\Generate\Count::class;
40 changes: 40 additions & 0 deletions core/components/fred/src/Processors/Generate/Count.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Fred\Processors\Generate;

use Fred\Model\FredThemedTemplate;
use MODX\Revolution\modResource;
use MODX\Revolution\Processors\Processor;

class Count extends Processor
{
public function checkPermissions()
{
return $this->modx->hasPermission('empty_cache');
}

public function process()
{
$theme = (int)$this->getProperty('theme', 0);

$c = $this->modx->newQuery(FredThemedTemplate::class);
$c->select($this->modx->getSelectColumns(FredThemedTemplate::class, 'FredThemedTemplate', '', ['template']));
if ($theme > 0) {
$c->where(['theme' => $theme]);
}
$c->prepare();
$c->stmt->execute();

$templates = $c->stmt->fetchAll(\PDO::FETCH_COLUMN, 0);
$templates = array_map('intval', $templates);
$templates = array_filter($templates);

if (empty($templates)) {
return $this->failure($this->modx->lexicon('fred.refresh_fail_template'));
}

$count = $this->modx->getCount(modResource::class, ['template:IN' => $templates]);

return $this->success('', ['total' => (int)$count]);
}
}
23 changes: 16 additions & 7 deletions core/components/fred/src/Processors/Generate/Refresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ public function checkPermissions()

public function process()
{
//allow larger sites to rebuild
ini_set('max_execution_time', 300);
/** @var Fred $fred */
$fred = $this->modx->services->get('fred');
ini_set('max_execution_time', 30);

//Clear Element Values
$this->modx->removeCollection(FredCache::class, []);
$offset = (int)$this->getProperty('offset', 0);
$limit = (int)$this->getProperty('limit', 10);
$isLast = (bool)$this->getProperty('isLast', false);
$theme = (int)$this->getProperty('theme', 0);

if ($offset === 0) {
$this->modx->removeCollection(FredCache::class, []);
}

$c = $this->modx->newQuery(FredThemedTemplate::class);
$c->select($this->modx->getSelectColumns(FredThemedTemplate::class, 'FredThemedTemplate', '', ['template']));
if ($theme > 0) {
$c->where(['theme' => $theme]);
}

$c->prepare();
$c->stmt->execute();
Expand All @@ -44,6 +50,7 @@ public function process()

$c = $this->modx->newQuery(modResource::class);
$c->where(['template:IN' => $templates]);
$c->limit($limit, $offset);
$results = $this->modx->getIterator(modResource::class, $c);

foreach ($results as $resource) {
Expand Down Expand Up @@ -86,7 +93,9 @@ public function process()
$this->modx->log(modX::LOG_LEVEL_INFO, $this->modx->lexicon('fred.refresh_id', ['id' => $resource->id]));
}

$this->modx->log(modX::LOG_LEVEL_INFO, $this->modx->lexicon('fred.refresh_complete'));
if ($isLast) {
$this->modx->log(modX::LOG_LEVEL_INFO, $this->modx->lexicon('fred.refresh_complete'));
}

return $this->success('');
}
Expand Down
40 changes: 40 additions & 0 deletions core/components/fred/src/v2/Processors/Generate/Count.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Fred\v2\Processors\Generate;

/**
* @package fred
* @subpackage processors
*/
class Count extends \modProcessor
{
public function checkPermissions()
{
return $this->modx->hasPermission('empty_cache');
}

public function process()
{
$theme = (int)$this->getProperty('theme', 0);

$c = $this->modx->newQuery('FredThemedTemplate');
$c->select($this->modx->getSelectColumns('FredThemedTemplate', 'FredThemedTemplate', '', ['template']));
if ($theme > 0) {
$c->where(['theme' => $theme]);
}
$c->prepare();
$c->stmt->execute();

$templates = $c->stmt->fetchAll(\PDO::FETCH_COLUMN, 0);
$templates = array_map('intval', $templates);
$templates = array_filter($templates);

if (empty($templates)) {
return $this->failure($this->modx->lexicon('fred.refresh_fail_template'));
}

$count = $this->modx->getCount('modResource', ['template:IN' => $templates]);

return $this->success('', ['total' => (int)$count]);
}
}
22 changes: 17 additions & 5 deletions core/components/fred/src/v2/Processors/Generate/Refresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ public function checkPermissions()

public function process()
{
//allow larger sites to rebuild
ini_set('max_execution_time', 300);
ini_set('max_execution_time', 30);

$offset = (int)$this->getProperty('offset', 0);
$limit = (int)$this->getProperty('limit', 10);
$isLast = (bool)$this->getProperty('isLast', false);
$theme = (int)$this->getProperty('theme', 0);

/** @var \Fred $fred */
$corePath = $this->modx->getOption('fred.core_path', null, $this->modx->getOption('core_path', null, MODX_CORE_PATH) . 'components/fred/');
$fred = $this->modx->getService(
Expand All @@ -28,11 +33,15 @@ public function process()
]
);

//Clear Element Values
$this->modx->removeCollection('FredCache', []);
if ($offset === 0) {
$this->modx->removeCollection('FredCache', []);
}

$c = $this->modx->newQuery('FredThemedTemplate');
$c->select($this->modx->getSelectColumns('FredThemedTemplate', 'FredThemedTemplate', '', ['template']));
if ($theme > 0) {
$c->where(['theme' => $theme]);
}

$c->prepare();
$c->stmt->execute();
Expand All @@ -47,6 +56,7 @@ public function process()

$c = $this->modx->newQuery('modResource');
$c->where(['template:IN' => $templates]);
$c->limit($limit, $offset);
$results = $this->modx->getIterator('modResource', $c);

foreach ($results as $resource) {
Expand Down Expand Up @@ -89,7 +99,9 @@ public function process()
$this->modx->log(\modX::LOG_LEVEL_INFO, $this->modx->lexicon('fred.refresh_id', ['id' => $resource->id]));
}

$this->modx->log(\modX::LOG_LEVEL_INFO, $this->modx->lexicon('fred.refresh_complete'));
if ($isLast) {
$this->modx->log(\modX::LOG_LEVEL_INFO, $this->modx->lexicon('fred.refresh_complete'));
}

return $this->success('');
}
Expand Down