Conditions | 29 |
Paths | 17080 |
Total Lines | 154 |
Code Lines | 101 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
259 | public function getTriggersList($forcedirtriggers = null) |
||
260 | { |
||
261 | global $conf, $langs, $db; |
||
262 | |||
263 | $files = array(); |
||
264 | $fullpath = array(); |
||
265 | $relpath = array(); |
||
266 | $iscoreorexternal = array(); |
||
267 | $modules = array(); |
||
268 | $orders = array(); |
||
269 | $i = 0; |
||
270 | |||
271 | $dirtriggers = array_merge(array('/core/triggers/'), $conf->modules_parts['triggers']); |
||
272 | if (is_array($forcedirtriggers)) { |
||
273 | $dirtriggers = $forcedirtriggers; |
||
274 | } |
||
275 | |||
276 | foreach ($dirtriggers as $reldir) { |
||
277 | $dir = dol_buildpath($reldir, 0); |
||
278 | $newdir = dol_osencode($dir); |
||
279 | |||
280 | // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call) |
||
281 | if (!is_dir($newdir)) { |
||
282 | continue; |
||
283 | } |
||
284 | |||
285 | $handle = opendir($newdir); |
||
286 | if (is_resource($handle)) { |
||
287 | while (($file = readdir($handle)) !== false) { |
||
288 | $reg = array(); |
||
289 | if (is_readable($newdir . '/' . $file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/', $file, $reg)) { |
||
290 | if (preg_match('/\.back$/', $file)) { |
||
291 | continue; |
||
292 | } |
||
293 | |||
294 | $part1 = $reg[1]; |
||
295 | $part2 = $reg[2]; |
||
296 | $part3 = $reg[3]; |
||
297 | |||
298 | $modName = 'Interface' . ucfirst($reg[3]); |
||
299 | //print "file=$file"; print "modName=$modName"; exit; |
||
300 | if (in_array($modName, $modules)) { |
||
301 | $langs->load("errors"); |
||
302 | print '<div class="error">' . $langs->trans("Error") . ' : ' . $langs->trans("ErrorDuplicateTrigger", $modName, "/htdocs/core/triggers/") . '</div>'; |
||
303 | } else { |
||
304 | include_once $newdir . '/' . $file; |
||
305 | } |
||
306 | |||
307 | $files[$i] = $file; |
||
308 | $fullpath[$i] = $dir . '/' . $file; |
||
309 | $relpath[$i] = preg_replace('/^\//', '', $reldir) . '/' . $file; |
||
310 | $iscoreorexternal[$i] = ($reldir == '/core/triggers/' ? 'internal' : 'external'); |
||
311 | $modules[$i] = $modName; |
||
312 | $orders[$i] = $part1 . '_' . $part2 . '_' . $part3; // Set sort criteria value |
||
313 | |||
314 | $i++; |
||
315 | } |
||
316 | } |
||
317 | closedir($handle); |
||
318 | } |
||
319 | } |
||
320 | |||
321 | asort($orders, SORT_NATURAL); |
||
322 | |||
323 | $triggers = array(); |
||
324 | $j = 0; |
||
325 | |||
326 | // Loop on each trigger |
||
327 | foreach ($orders as $key => $value) { |
||
328 | $modName = $modules[$key]; |
||
329 | if (empty($modName)) { |
||
330 | continue; |
||
331 | } |
||
332 | |||
333 | if (!class_exists($modName)) { |
||
334 | print 'Error: A trigger file was found but its class "' . $modName . '" was not found.' . "<br>\n"; |
||
335 | continue; |
||
336 | } |
||
337 | |||
338 | $text = ''; |
||
339 | |||
340 | try { |
||
341 | $objMod = new $modName($db); |
||
342 | |||
343 | if (is_subclass_of($objMod, 'DolibarrTriggers')) { |
||
344 | // Define disabledbyname and disabledbymodule |
||
345 | $disabledbyname = 0; |
||
346 | $disabledbymodule = 1; |
||
347 | $module = ''; |
||
348 | |||
349 | // Check if trigger file is disabled by name |
||
350 | if (preg_match('/NORUN$/i', $files[$key])) { |
||
351 | $disabledbyname = 1; |
||
352 | } |
||
353 | // Check if trigger file is for a particular module |
||
354 | if (preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/i', $files[$key], $reg)) { |
||
355 | $module = preg_replace('/^mod/i', '', $reg[2]); |
||
356 | if (strtolower($module) == 'all') { |
||
357 | $disabledbymodule = 0; |
||
358 | } elseif (!isModEnabled(strtolower($module))) { |
||
359 | $disabledbymodule = 2; |
||
360 | } |
||
361 | $triggers[$j]['module'] = strtolower($module); |
||
362 | } |
||
363 | |||
364 | // We set info of modules |
||
365 | $triggers[$j]['picto'] = (!empty($objMod->picto)) ? img_object('', $objMod->picto, 'class="valignmiddle pictomodule "') : img_object('', 'generic', 'class="valignmiddle pictomodule "'); |
||
366 | $triggers[$j]['file'] = $files[$key]; |
||
367 | $triggers[$j]['fullpath'] = $fullpath[$key]; |
||
368 | $triggers[$j]['relpath'] = $relpath[$key]; |
||
369 | $triggers[$j]['iscoreorexternal'] = $iscoreorexternal[$key]; |
||
370 | $triggers[$j]['version'] = $objMod->getVersion(); |
||
371 | $triggers[$j]['status'] = img_picto($langs->trans("Active"), 'tick'); |
||
372 | if ($disabledbyname > 0 || $disabledbymodule > 1) { |
||
373 | $triggers[$j]['status'] = ''; |
||
374 | } |
||
375 | |||
376 | $text = '<b>' . $langs->trans("Description") . ':</b><br>'; |
||
377 | $text .= $objMod->getDesc() . '<br>'; |
||
378 | $text .= '<br><b>' . $langs->trans("Status") . ':</b><br>'; |
||
379 | if ($disabledbyname == 1) { |
||
380 | $text .= $langs->trans("TriggerDisabledByName") . '<br>'; |
||
381 | if ($disabledbymodule == 2) { |
||
382 | $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module) . '<br>'; |
||
383 | } |
||
384 | } else { |
||
385 | if ($disabledbymodule == 0) { |
||
386 | $text .= $langs->trans("TriggerAlwaysActive") . '<br>'; |
||
387 | } |
||
388 | if ($disabledbymodule == 1) { |
||
389 | $text .= $langs->trans("TriggerActiveAsModuleActive", $module) . '<br>'; |
||
390 | } |
||
391 | if ($disabledbymodule == 2) { |
||
392 | $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module) . '<br>'; |
||
393 | } |
||
394 | } |
||
395 | } else { |
||
396 | $triggers[$j]['picto'] = (!empty($objMod->picto)) ? img_object('', $objMod->picto, 'class="valignmiddle pictomodule "') : img_object('', 'generic', 'class="valignmiddle pictomodule "'); |
||
397 | $triggers[$j]['file'] = $files[$key]; |
||
398 | $triggers[$j]['fullpath'] = $fullpath[$key]; |
||
399 | $triggers[$j]['relpath'] = $relpath[$key]; |
||
400 | $triggers[$j]['status'] = img_picto('Error: Trigger ' . $modName . ' does not extends DolibarrTriggers', 'warning'); |
||
401 | |||
402 | //print 'Error: Trigger '.$modName.' does not extends DolibarrTriggers<br>'; |
||
403 | $text = 'Error: Trigger ' . $modName . ' does not extends DolibarrTriggers'; |
||
404 | } |
||
405 | } catch (Exception $e) { |
||
406 | print $e->getMessage(); |
||
407 | } |
||
408 | |||
409 | $triggers[$j]['info'] = $text; |
||
410 | $j++; |
||
411 | } |
||
412 | return $triggers; |
||
413 | } |
||
415 |