diff --git a/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl b/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl
index fe7d76e13..1f67811cf 100644
--- a/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl
+++ b/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl
@@ -25,7 +25,7 @@
diff --git a/cache/push/activity b/cache/push/activity
new file mode 100644
index 000000000..e69de29bb
diff --git a/classes/Tools.php b/classes/Tools.php
index bf8becb99..4d7a14a85 100644
--- a/classes/Tools.php
+++ b/classes/Tools.php
@@ -2572,6 +2572,33 @@ exit;
}
return $fileAttachment;
}
+
+ public static function changeFileMTime($file_name, $time = null)
+ {
+ if ($time === null)
+ $time = time();
+
+ touch($file_name, $time);
+ }
+
+ public static function waitUntilFileIsModified($file_name, $timeout = 180)
+ {
+ @ini_set('max_execution_time', $timeout);
+ if (($time_limit = ini_get('max_execution_time')) === null)
+ $time_limit = 30;
+
+ $time_limit -= 5;
+ $start_time = microtime(true);
+ $last_modified = filemtime($file_name);
+
+ while(true)
+ {
+ if (((microtime(true) - $start_time) > $time_limit) || filemtime($file_name) > $last_modified)
+ break;
+ clearstatcache();
+ usleep(300);
+ }
+ }
}
/**
diff --git a/controllers/admin/AdminDashboardController.php b/controllers/admin/AdminDashboardController.php
index 9c0f24684..5738c83ee 100644
--- a/controllers/admin/AdminDashboardController.php
+++ b/controllers/admin/AdminDashboardController.php
@@ -71,16 +71,17 @@ class AdminDashboardControllerCore extends AdminController
);
return parent::renderView();
}
-
+
public function ajaxProcessRefreshDashboard()
{
$id_module = null;
if ($module = Tools::getValue('module'))
$id_module = Module::getInstanceByName($module)->id;
-
+
$params = array(
'date_from' => $this->context->employee->stats_date_from,
'date_to' => $this->context->employee->stats_date_to,
+ 'use_push' => (int)Tools::getValue('use_push')
);
die(Tools::jsonEncode(Hook::exec('dashboardData', $params, $id_module, true)));
diff --git a/js/admin-dashboard.js b/js/admin-dashboard.js
index 96c040210..b22d553a1 100644
--- a/js/admin-dashboard.js
+++ b/js/admin-dashboard.js
@@ -24,8 +24,31 @@
$(document).ready( function () {
refreshDashbard();
+ if (use_push)
+ launchPush();
});
+function launchPush()
+{
+ $.ajax({
+ url : dashboard_ajax_url,
+ data : {
+ ajax:true,
+ action:'refreshDashboard',
+ module:'dashactivity',
+ use_push:1,
+ },
+ dataType: 'json',
+ success : function(widgets){
+ for (var name in widgets)
+ {
+ for (data_type in widgets[name])
+ window[data_type](widgets[name][data_type]);
+ }
+ launchPush();
+ },
+ });
+}
function refreshDashbard(module_name)
{
diff --git a/modules/dashactivity/dashactivity.php b/modules/dashactivity/dashactivity.php
index 677558b64..cbbbd20e3 100644
--- a/modules/dashactivity/dashactivity.php
+++ b/modules/dashactivity/dashactivity.php
@@ -36,13 +36,23 @@ class Dashactivity extends Module
$this->tab = '';
$this->version = '0.1';
$this->author = 'PrestaShop';
-
+ $this->push_filename = _PS_CACHE_DIR_.'push/activity';
+
parent::__construct();
}
public function install()
{
- if (!parent::install() || !$this->registerHook('dashboardZoneOne') || !$this->registerHook('dashboardData'))
+ if (!parent::install()
+ || !$this->registerHook('dashboardZoneOne')
+ || !$this->registerHook('dashboardData')
+ || !$this->registerHook('actionObjectOrderAddAfter')
+ || !$this->registerHook('actionObjectCustomerAddAfter')
+ || !$this->registerHook('actionObjectCustomerMessageAddAfter')
+ || !$this->registerHook('actionObjectCustomerThreadAddAfter')
+ || !$this->registerHook('actionObjectOrderReturnAddAfter')
+
+ )
return false;
return true;
}
@@ -54,6 +64,9 @@ class Dashactivity extends Module
public function hookDashboardData($params)
{
+ if ($params['use_push'])
+ Tools::waitUntilFileIsModified($this->push_filename, 30);
+
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
{
@@ -187,4 +200,29 @@ class Dashactivity extends Module
)
);
}
-}
\ No newline at end of file
+
+ public function hookActionObjectCustomerMessageAddAfter($params)
+ {
+ return $this->hookActionObjectOrderAddAfter($params);
+ }
+
+ public function hookActionObjectCustomerThreadAddAfter($params)
+ {
+ return $this->hookActionObjectOrderAddAfter($params);
+ }
+
+ public function hookActionObjectCustomerAddAfter($params)
+ {
+ return $this->hookActionObjectOrderAddAfter($params);
+ }
+
+ public function hookActionObjectOrderReturnAddAfter($params)
+ {
+ return $this->hookActionObjectOrderAddAfter($params);
+ }
+
+ public function hookActionObjectOrderAddAfter($params)
+ {
+ Tools::changeFileMTime($this->push_filename);
+ }
+}