diff --git a/htdocs/core/boxes/box_scheduled_jobs.php b/htdocs/core/boxes/box_scheduled_jobs.php new file mode 100644 index 00000000000..1739c6ab8e9 --- /dev/null +++ b/htdocs/core/boxes/box_scheduled_jobs.php @@ -0,0 +1,181 @@ + + * Copyright (C) 2005-2017 Laurent Destailleur + * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2017 Nicolas Zabouri + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/boxes/box_scheduled_jobs.php + * \ingroup task + * \brief Widget of scheduled jobs + */ + +include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php'; + + +/** + * Class to manage the box to show last contracted products/services lines + */ +class box_scheduled_jobs extends ModeleBoxes +{ + public $boxcode = "scheduledjobs"; + public $boximg = "object_cron"; + public $boxlabel = "BoxScheduledJobs"; + public $depends = array("cron"); + + /** + * @var DoliDB Database handler. + */ + public $db; + + public $param; + + public $info_box_head = array(); + public $info_box_contents = array(); + + + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + public function __construct($db, $param) + { + global $user; + + $this->db = $db; + + $this->hidden = !($user->rights->service->lire && $user->rights->contrat->lire); + } + + /** + * Load data into info_box_contents array to show array later. + * + * @param int $max Maximum number of records to load + * @return void + */ + public function loadBox($max = 5) + { + global $user, $langs, $conf; + $this->max = $max; + $langs->load("cron"); + $this->info_box_head = array('text' => $langs->trans("BoxScheduledJobs", $max)); + + if ($user->rights->cron->read) { + include_once DOL_DOCUMENT_ROOT . '/cron/class/cronjob.class.php'; + $cronstatic = new Cronjob($this->db); + $nomUrlArray; + + $result = 0; + $sql = "SELECT t.rowid, t.datelastrun, t.datenextrun"; + $sql .= ", t.label, t.status, t.lastresult"; + $sql .= " FROM " . MAIN_DB_PREFIX . "cronjob as t"; + $sql .= $this->db->order("t.datelastrun", "DESC"); + + $result = $this->db->query($sql); + $line = 0; + $nbjobsinerror = 0; + if ($result) { + $num = $this->db->num_rows($result); + $i = 0; + while ($i < $num) { + $objp = $this->db->fetch_object($result); + if ($line == 0 || $objp->datenextrun < $cronstatic->datenextrun) { + $cronstatic->id = $objp->rowid; + $cronstatic->ref = $objp->rowid; + $cronstatic->status = $objp->status; + $cronstatic->datenextrun = $objp->datenextrun; + $cronstatic->datelastrun = $objp->datelastrun; + } + if ($line == 0) { + $resultarray[$line] = array( + $langs->trans("LastExecutedScheduledJob"), + $cronstatic->getNomUrl(1), + $this->db->jdate($cronstatic->datelastrun), + $cronstatic->status + ); + $line++; + } + if (!empty($objp->lastresult)) { + $nbjobsinerror++; + } + $i++; + } + $resultarray[$line] = array( + $langs->trans("NextScheduledJobExecute"), + $cronstatic->getNomUrl(1), + $this->db->jdate($cronstatic->datenextrun), + $cronstatic->status + ); + $line = 0; + while ($line < 2) { + $this->info_box_contents[$line][] = array( + 'td' => 'class="left"', + 'text' => $resultarray[$line][0] + ); + + $this->info_box_contents[$line][] = array( + 'td' => 'class="left"', + 'textnoformat' => $resultarray[$line][1] + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'textnoformat' => dol_print_date($resultarray[$line][2], "dayhoursec") + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right" ', + 'textnoformat' => empty($resultarray[$line][3]) ? $langs->trans("Disabled") : $langs->trans("Scheduled") + ); + $line++; + } + $this->info_box_contents[$line][] = array( + 'td' => 'class="left" colspan="2"', + 'text' => $langs->trans("NumberScheduledJobError") + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"colspan="2"', + 'text' => $nbjobsinerror + ); + } else { + $this->info_box_contents[0][0] = array( + 'td' => '', + 'maxlength' => 500, + 'text' => ($this->db->error() . ' sql=' . $sql) + ); + } + } else { + $this->info_box_contents[0][0] = array( + 'td' => 'class="nohover opacitymedium left"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); + } + } + + /** + * Method to show box + * + * @param array $head Array with properties of box title + * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string + * @return string + */ + public function showBox($head = null, $contents = null, $nooutput = 0) + { + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + } +} diff --git a/htdocs/core/modules/modCron.class.php b/htdocs/core/modules/modCron.class.php index b8b281b79d1..deb140f76e4 100644 --- a/htdocs/core/modules/modCron.class.php +++ b/htdocs/core/modules/modCron.class.php @@ -91,7 +91,9 @@ class modCron extends DolibarrModules // Boxes //------ - $this->boxes = array(); + $this->boxes = array( + 0 => array('file' => 'box_scheduled_jobs.php', 'enabledbydefaulton' => 'Home') + ); // Cronjobs $this->cronjobs = array( diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index 6c3c6e04acb..e082eb48b27 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -551,4 +551,6 @@ CREATE TABLE llx_session( --INSERT INTO llx_boxes_def(file, entity) VALUES ('box_funnel_of_prospection.php',1); --INSERT INTO llx_boxes_def(file, entity) VALUES ('box_customers_outstanding_bill_reached.php', 1); -ALTER TABLE llx_product_fournisseur_price ADD COLUMN packaging varchar(64); \ No newline at end of file +ALTER TABLE llx_product_fournisseur_price ADD COLUMN packaging varchar(64); + +INSERT INTO llx_boxes_def(file, entity) VALUES ('box_scheduled_jobs.php',1); \ No newline at end of file diff --git a/htdocs/langs/en_US/boxes.lang b/htdocs/langs/en_US/boxes.lang index 11a22879367..b8ba5073d03 100644 --- a/htdocs/langs/en_US/boxes.lang +++ b/htdocs/langs/en_US/boxes.lang @@ -50,6 +50,7 @@ BoxTitleLastOutstandingBillReached=Customers with maximum outstanding exceeded BoxGlobalActivity=Global activity (invoices, proposals, orders) BoxGoodCustomers=Good customers BoxTitleGoodCustomers=%s Good customers +BoxScheduledJobs=Scheduled jobs BoxTitleFunnelOfProspection=Lead funnel FailedToRefreshDataInfoNotUpToDate=Failed to refresh RSS flux. Latest successful refresh date: %s LastRefreshDate=Latest refresh date diff --git a/htdocs/langs/en_US/cron.lang b/htdocs/langs/en_US/cron.lang index 9bf918a73a3..2ebdda1e685 100644 --- a/htdocs/langs/en_US/cron.lang +++ b/htdocs/langs/en_US/cron.lang @@ -84,4 +84,8 @@ MakeLocalDatabaseDumpShort=Local database backup MakeLocalDatabaseDump=Create a local database dump. Parameters are: compression ('gz' or 'bz' or 'none'), backup type ('mysql', 'pgsql', 'auto'), 1, 'auto' or filename to build, number of backup files to keep WarningCronDelayed=Attention, for performance purpose, whatever is next date of execution of enabled jobs, your jobs may be delayed to a maximum of %s hours, before being run. DATAPOLICYJob=Data cleaner and anonymizer -JobXMustBeEnabled=Job %s must be enabled \ No newline at end of file +JobXMustBeEnabled=Job %s must be enabled +# Cron Boxes +LastExecutedScheduledJob=Last executed scheduled job +NextScheduledJobExecute=Next scheduled job to execute +NumberScheduledJobError=Number of scheduled jobs in error