ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilWorkflowDefinitionRepository.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 {
9  const FILE_EXTENSTION_BPMN2 = 'bpmn2';
10  const FILE_EXTENSTION_PHP = 'php';
11 
12  const FILE_PREFIX = 'wsd.il';
13 
17  protected $db;
18 
22  protected $fs;
23 
27  protected $path;
28 
32  protected $definitionsLoaded = false;
33 
37  protected $definitions = [];
38 
45  public function __construct(\ilDBInterface $db, \ILIAS\Filesystem\Filesystems $fs, $path)
46  {
47  $this->db = $db;
48  $this->fs = $fs;
49  $this->path = $path;
50  }
51 
55  protected function lazyLoadWorkflowDefinitions()
56  {
57  if ($this->definitionsLoaded) {
58  return;
59  }
60  $this->definitionsLoaded = true;
61 
62  $query = 'SELECT workflow_class, COUNT(workflow_id) total, SUM(active) active
63  FROM wfe_workflows
64  GROUP BY workflow_class';
65  $result = $this->db->query($query);
66 
67  $stats = array();
68  while ($row = $this->db->fetchAssoc($result)) {
69  $stats[$row['workflow_class']] = array('total' => $row['total'], 'active' => $row['active']);
70  }
71 
72  if (!$this->fs->storage()->hasDir($this->path)) {
73  $this->definitions = array();
74  return;
75  }
76 
77  $contents = $this->fs->storage()->listContents($this->path, false);
78  $contents = array_filter($contents, function (ILIAS\Filesystem\DTO\Metadata $file) {
79  if (!$file->isFile()) {
80  return false;
81  }
82 
83  $fileParts = pathinfo($file->getPath());
84 
85  return $fileParts['extension'] === self::FILE_EXTENSTION_BPMN2;
86  });
87 
88  $prefixLength = strlen(self::FILE_PREFIX);
89 
90  $definitions = [];
91  foreach ($contents as $file) {
92  $fileParts = pathinfo($file->getPath());
93  $extensionLength = strlen($fileParts['extension']) + 1;
94 
95  $definition = [];
96 
97  $definition['file'] = $fileParts['basename'];
98  $definition['id'] = $fileParts['filename'];
99 
100  $parts = explode('_', substr($fileParts['basename'], $prefixLength, $extensionLength * -1));
101 
102  $definition['status'] = 1;
103  if (!$this->fs->storage()->has($this->path . '/' . $definition['id'] . '.php')) {
104  $definition['status'] = 0;
105  }
106  $definition['version'] = substr(array_pop($parts), 1);
107  $definition['title'] = implode(' ', $parts);
108  $definition['instances'] = $stats[$definition['id'] . '.php'];
109 
110  $definitions[$definition['id']] = $definition;
111  }
112 
113  $this->definitions = $definitions;
114  }
115 
119  public function getAll()
120  {
122  return $this->definitions;
123  }
124 
129  public function has($id)
130  {
132  return isset($this->definitions[$id]);
133  }
134 
140  public function getById($id)
141  {
143  if (!$this->has($id)) {
144  throw new \ilWorkflowEngineException(sprintf("Could not find definition for id: %s", $id));
145  }
146 
147  return $this->definitions[$id];
148  }
149 }
$result
__construct(\ilDBInterface $db, \ILIAS\Filesystem\Filesystems $fs, $path)
ilWorkflowDefinitionRepository constructor.
Class BaseForm.
if(!array_key_exists('StateId', $_REQUEST)) $id
Class ilWorkflowDefinitionRepository.
$query
$row
Class FlySystemFileAccessTest.