Merge pull request #15734 from Hystepik/develop#3
Close #15729 : Widget scheduled jobs
This commit is contained in:
commit
1c648947d1
181
htdocs/core/boxes/box_scheduled_jobs.php
Normal file
181
htdocs/core/boxes/box_scheduled_jobs.php
Normal file
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2017 Nicolas Zabouri <info@inovea-conseil.com>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \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);
|
||||
}
|
||||
}
|
||||
@ -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(
|
||||
|
||||
@ -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);
|
||||
ALTER TABLE llx_product_fournisseur_price ADD COLUMN packaging varchar(64);
|
||||
|
||||
INSERT INTO llx_boxes_def(file, entity) VALUES ('box_scheduled_jobs.php',1);
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user