Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
JobsToJobsCollectionViewUtil.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
42  {
46  const STATUS_NOT_RUNNING = 1;
47 
53 
57  const STATUS_IN_PROCESS = 3;
58 
59  const NON_MONITOR_JOBS_CACHE_ID = 'NonMonitorJobsModelClassNames';
60 
65  public static function getMonitorJobData()
66  {
67  return self::getJobDataByType('Monitor');
68  }
69 
74  public static function getNonMonitorJobsData()
75  {
76  $jobClassNames = static::getNonMonitorJobClassNames();
77  $jobsData = array();
78  foreach ($jobClassNames as $jobClassName)
79  {
80  if ($jobClassName::showInJobManagerToRunManually())
81  {
82  $jobsData[$jobClassName::getType()] = self::getJobDataByType($jobClassName::getType());
83  }
84  }
85  return $jobsData;
86  }
87 
88  public static function getNonMonitorJobClassNames()
89  {
90  try
91  {
92  $jobClassNames = GeneralCache::getEntry(self::NON_MONITOR_JOBS_CACHE_ID);
93  }
94  catch (NotFoundException $e)
95  {
96  $jobClassNames = array();
97  $modules = Module::getModuleObjects();
98  foreach ($modules as $module)
99  {
100  $jobsClassNames = $module::getAllClassNamesByPathFolder('jobs');
101  foreach ($jobsClassNames as $jobClassName)
102  {
103  $classToEvaluate = new ReflectionClass($jobClassName);
104  if (is_subclass_of($jobClassName, 'BaseJob') && !$classToEvaluate->isAbstract() &&
105  $jobClassName != 'MonitorJob')
106  {
107  $jobClassNames[] = $jobClassName;
108  }
109  }
110  }
111  GeneralCache::cacheEntry(self::NON_MONITOR_JOBS_CACHE_ID, $jobClassNames);
112  }
113  return $jobClassNames;
114  }
115 
116  protected static function getJobDataByType($type)
117  {
118  assert('is_string($type) && $type != ""');
119  $jobClassName = $type . 'Job';
120  $lastCompletedJobLog = self::getLastCompletedJobLogByType($type);
121  $jobInProcess = self::getIfJobIsInProcessOtherwiseReturnNullByType($type);
122  $jobData = array();
123  $jobData['label'] = $jobClassName::getDisplayName();
124  $jobData['lastCompletedRunEncodedContent'] = self::makeLastCompletedRunEncodedContentByJobLog($lastCompletedJobLog);
125  $jobData['statusContent'] = self::makeStatusContentByJobInProcess($jobInProcess);
126  $jobData['status'] = self::resolveStatusByJobInProcess($jobInProcess);
127  $jobData['recommendedFrequencyContent'] = $jobClassName::getRecommendedRunFrequencyContent();
128  return $jobData;
129  }
130 
131  protected static function getIfJobIsInProcessOtherwiseReturnNullByType($type)
132  {
133  assert('is_string($type) && $type != ""');
134  try
135  {
136  $jobInProcess = JobInProcess::getByType($type);
137  }
138  catch (NotFoundException $e)
139  {
140  $jobInProcess = null;
141  }
142  return $jobInProcess;
143  }
144 
145  protected static function makeLastCompletedRunEncodedContentByJobLog($jobLog)
146  {
147  assert('$jobLog instanceof JobLog || $jobLog == null');
148  if ($jobLog == null)
149  {
150  return ZurmoHtml::wrapLabel(Zurmo::t('Core', 'Never'), 'jobHasNeverRun');
151  }
152  if ($jobLog != null && $jobLog->status == JobLog::STATUS_COMPLETE_WITH_ERROR)
153  {
154  $content = DateTimeUtil::
155  convertDbFormattedDateTimeToLocaleFormattedDisplay($jobLog->createdDateTime);
156  $content .= ' ' . Zurmo::t('JobsManagerModule', '[with errors]');
157  $content = ZurmoHtml::wrapLabel($content, 'jobHasErrors');
158  }
159  else
160  {
161  $content = DateTimeUtil::
162  convertDbFormattedDateTimeToLocaleFormattedDisplay($jobLog->createdDateTime);
163  $content = ZurmoHtml::wrapLabel($content, 'jobRanSuccessfully');
164  }
165  return $content;
166  }
167 
168  protected static function makeStatusContentByJobInProcess($jobInProcess)
169  {
170  assert('$jobInProcess instanceof JobInProcess || $jobInProcess == null');
171  if ($jobInProcess != null && JobsManagerUtil::isJobInProcessOverThreshold($jobInProcess, $jobInProcess->type))
172  {
173  return Zurmo::t('JobsManagerModule', 'In Process (Stuck)');
174  }
175  elseif ($jobInProcess != null)
176  {
177  $startedDateTimeContent = DateTimeUtil::
178  convertDbFormattedDateTimeToLocaleFormattedDisplay($jobInProcess->createdDateTime);
179  return Zurmo::t('JobsManagerModule', 'In Process [Started: {startedDateTime}]',
180  array('{startedDateTime}' => $startedDateTimeContent));
181  }
182  else
183  {
184  return Zurmo::t('JobsManagerModule', 'Idle');
185  }
186  }
187 
188  protected static function resolveStatusByJobInProcess($jobInProcess)
189  {
190  assert('$jobInProcess instanceof JobInProcess || $jobInProcess == null');
191  if ($jobInProcess != null && JobsManagerUtil::isJobInProcessOverThreshold($jobInProcess, $jobInProcess->type))
192  {
193  return self::STATUS_IN_PROCESS_STUCK;
194  }
195  elseif ($jobInProcess != null)
196  {
197  return self::STATUS_IN_PROCESS;
198  }
199  else
200  {
201  return self::STATUS_NOT_RUNNING;
202  }
203  }
204 
205  protected static function getLastCompletedJobLogByType($type)
206  {
207  assert('is_string($type) && $type != ""');
208  $searchAttributeData = array();
209  $searchAttributeData['clauses'] = array(
210  1 => array(
211  'attributeName' => 'type',
212  'operatorType' => 'equals',
213  'value' => $type,
214  ),
215  );
216  $searchAttributeData['structure'] = '1';
217  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('JobLog');
218  $sort = RedBeanModelDataProvider::
219  resolveSortAttributeColumnName('JobLog', $joinTablesAdapter, 'createdDateTime');
220  $where = RedBeanModelDataProvider::makeWhere('JobLog', $searchAttributeData, $joinTablesAdapter);
221  $models = JobLog::getSubset($joinTablesAdapter, null, 1, $where, $sort . ' desc');
222  if (count($models) > 1)
223  {
224  throw new NotSupportedException();
225  }
226  if (count($models) == 0)
227  {
228  return null;
229  }
230  return $models[0];
231  }
232  }
233 ?>
static wrapLabel($label, $class= 'z-label')
Definition: ZurmoHtml.php:656
static getModuleObjects()
Definition: Module.php:51
static getByType($type)
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getSubset(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $offset=null, $count=null, $where=null, $orderBy=null, $modelClassName=null, $selectDistinct=false)
static isJobInProcessOverThreshold(JobInProcess $jobInProcess, $type)
Generated on Tue Sep 22 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.