Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/theyoungdesigners_com/modules/refresh/ |
Upload File : |
<?php
namespace modules\refresh;
class main extends \moduleMain {
use \modules\input\traits {
\modules\input\traits::__construct as __ConstructInput;
}
use \modules\output\traits {
\modules\output\traits::__construct as __ConstructOutput;
}
private $active = FALSE;
public function __construct() {
parent::__construct(__DIR__);
$this->__ConstructInput();
$this->__ConstructOutput();
}
// register hooks
public function Activate() {
hook_add('menu.admin', [$this, '__admin_menu'], 96);
hook_add('html.prepare', [$this, '__html_prepare']);
hook_add('component.add', [$this, '__component']);
}
public function __component(&$status, $requested) {
if ($requested == 'refresh') {
$this->active = TRUE;
}
}
// add admin menu button - but only on the slave (staging) site
public function __admin_menu(&$menu) {
if (!empty($this->settings['master'])) {
$menu[] = [
'caption' => 'Refresh Database',
'href' => '/admin/refresh-data',
'hint' => 'Import changed data from the Live site', // clear out tables if you want complete refresh. Do not clear out `config`, `events` or `_migration`
'icon' => '<i class="fas fa-database"></i>',
's' => 0
];
}
}
// add the javascript to process the tables, one at a time
// only if active
public function __html_prepare($modulemain) {
$base = $modulemain->StaticUriModule(__DIR__);
if ($this->active) {
$id = $modulemain->IncludeFile('');
$text = <<<'BLOCK'
function refresh_doit() {
// get first unchecked
let $item = $('.list-tables input[name="table[]"]:checked').first();
if ($item.length) {
$item.prop('checked', false);
let $container = $item.closest('label');
let $span = $container.find('span.item');
$span.addClass('hilite'); // add ellipsis??
let tablename = $item.val();
$.ajax({
dataType: 'json',
async: true,
url: '/admin/refresh-data', // check tablename again
data: {
key: tablename,
},
type: 'POST'
}).done(function(data) {
$span.removeClass('hilite').addClass('disabled');
setTimeout(function() {
refresh_doit();
}, 100);
});
}
}
$(document).on('loaded.template', function(event, page_data, $container) {
$container.on('click', '.action-refresh', function(e) {
e.preventDefault();
refresh_doit();
});
});
BLOCK;
$id->JavascriptCommand($text, 0);
}
}
// retrieve info about a section of a table
final function table_summary($tablename = '', $start = 0) {
// get authorization
set_time_limit(0);
$model_refresh = $this->loadModel('refresh_model');
$auth = $_SERVER['HTTP_X_AUTH'] ?? '';
$res = $model_refresh->checkAuth($auth, $tablename);
if (is_null($res)) {
if ($this->__INPUT->isPost()) {
$keys = $_POST['key'] ?? [];
$res = $model_refresh->returnChangedRows($tablename, $keys);
} else {
$res = $model_refresh->generateTableSummary($tablename, $start);
}
}
header('Content-type: application/json');
die(json_encode($res, JSON_UNESCAPED_SLASHES));
}
}