Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       82.61%  | 
       95 / 115  | 
               | 
       66.67%  | 
       10 / 15  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| ProcessStatusArchived |         | 
       82.61%  | 
       95 / 115  | 
               | 
       66.67%  | 
       10 / 15  | 
       27.03 |         | 
       0.00%  | 
       0 / 1  | 
      
| readArchivedEntity |         | 
       88.89%  | 
       8 / 9  | 
               | 
       0.00%  | 
       0 / 1  | 
       2.01 | |||
| readListByScopeId |         | 
       100.00%  | 
       5 / 5  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| readListByDate |         | 
       100.00%  | 
       5 / 5  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| readListByScopeAndDate |         | 
       0.00%  | 
       0 / 6  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| readListByScopesAndDates |         | 
       0.00%  | 
       0 / 6  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| deleteAllToday |         | 
       0.00%  | 
       0 / 1  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| readListForStatistic |         | 
       100.00%  | 
       6 / 6  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| readListIsMissed |         | 
       100.00%  | 
       5 / 5  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| readListWithAppointment |         | 
       100.00%  | 
       5 / 5  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| readResolvedList |         | 
       100.00%  | 
       10 / 10  | 
               | 
       100.00%  | 
       1 / 1  | 
       5 | |||
| writeEntityFinished |         | 
       100.00%  | 
       13 / 13  | 
               | 
       100.00%  | 
       1 / 1  | 
       3 | |||
| writeArchivedProcessToStatistic |         | 
       100.00%  | 
       16 / 16  | 
               | 
       100.00%  | 
       1 / 1  | 
       2 | |||
| writeNewArchivedProcess |         | 
       100.00%  | 
       15 / 15  | 
               | 
       100.00%  | 
       1 / 1  | 
       2 | |||
| writeXRequestsArchived |         | 
       100.00%  | 
       7 / 7  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| anonymizeNames |         | 
       0.00%  | 
       0 / 6  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| 1 | <?php | 
| 2 | |
| 3 | namespace BO\Zmsdb; | 
| 4 | |
| 5 | use BO\Zmsentities\Processarchived as Entity; | 
| 6 | use BO\Zmsentities\Collection\ProcessList as Collection; | 
| 7 | |
| 8 | /** | 
| 9 | * | 
| 10 | */ | 
| 11 | class ProcessStatusArchived extends Process | 
| 12 | { | 
| 13 | public function readArchivedEntity($archiveId, $resolveReferences = 0) | 
| 14 | { | 
| 15 | if (!$archiveId) { | 
| 16 | return null; | 
| 17 | } | 
| 18 | $query = new Query\ProcessStatusArchived(Query\Base::SELECT); | 
| 19 | $query->addEntityMapping() | 
| 20 | ->addResolvedReferences($resolveReferences) | 
| 21 | ->addConditionArchiveId($archiveId); | 
| 22 | $archive = $this->fetchOne($query, new Entity()); | 
| 23 | $archive = $this->readResolvedReferences($archive, $resolveReferences); | 
| 24 | return $archive; | 
| 25 | } | 
| 26 | |
| 27 | public function readListByScopeId($scopeId, $resolveReferences = 0) | 
| 28 | { | 
| 29 | $query = new Query\ProcessStatusArchived(Query\Base::SELECT); | 
| 30 | $query->addEntityMapping() | 
| 31 | ->addResolvedReferences($resolveReferences) | 
| 32 | ->addConditionScopeId($scopeId); | 
| 33 | return $this->readResolvedList($query, $resolveReferences); | 
| 34 | } | 
| 35 | |
| 36 | public function readListByDate($dateTime, $resolveReferences = 0) | 
| 37 | { | 
| 38 | $query = new Query\ProcessStatusArchived(Query\Base::SELECT); | 
| 39 | $query->addEntityMapping() | 
| 40 | ->addResolvedReferences($resolveReferences) | 
| 41 | ->addConditionTime($dateTime); | 
| 42 | return $this->readResolvedList($query, $resolveReferences); | 
| 43 | } | 
| 44 | |
| 45 | public function readListByScopeAndDate($scopeId, $dateTime, $resolveReferences = 0) | 
| 46 | { | 
| 47 | $query = new Query\ProcessStatusArchived(Query\Base::SELECT); | 
| 48 | $query->addEntityMapping() | 
| 49 | ->addConditionScopeId($scopeId) | 
| 50 | ->addResolvedReferences($resolveReferences) | 
| 51 | ->addConditionTime($dateTime); | 
| 52 | return $this->readResolvedList($query, $resolveReferences); | 
| 53 | } | 
| 54 | |
| 55 | public function readListByScopesAndDates($scopeIds, $dateTimes, $resolveReferences = 0) | 
| 56 | { | 
| 57 | $query = new Query\ProcessStatusArchivedToday(Query\Base::SELECT); | 
| 58 | $query->addEntityMapping() | 
| 59 | ->addConditionScopeIds($scopeIds) | 
| 60 | ->addResolvedReferences($resolveReferences) | 
| 61 | ->addConditionTimes($dateTimes); | 
| 62 | |
| 63 | return $this->readResolvedList($query, $resolveReferences); | 
| 64 | } | 
| 65 | |
| 66 | public function deleteAllToday(): bool | 
| 67 | { | 
| 68 | return (bool)$this->perform(Query\ProcessStatusArchivedToday::DELETE_ALL); | 
| 69 | } | 
| 70 | |
| 71 | public function readListForStatistic($dateTime, \BO\Zmsentities\Scope $scope, $limit = 500, $resolveReferences = 0) | 
| 72 | { | 
| 73 | $query = new Query\ProcessStatusArchived(Query\Base::SELECT); | 
| 74 | $query->addEntityMapping() | 
| 75 | ->addResolvedReferences($resolveReferences) | 
| 76 | ->addJoinStatisticFailed($dateTime, $scope) | 
| 77 | ->addLimit($limit); | 
| 78 | return $this->readResolvedList($query, $resolveReferences); | 
| 79 | } | 
| 80 | |
| 81 | public function readListIsMissed($isMissed = 1, $resolveReferences = 0) | 
| 82 | { | 
| 83 | $query = new Query\ProcessStatusArchived(Query\Base::SELECT); | 
| 84 | $query->addEntityMapping() | 
| 85 | ->addResolvedReferences($resolveReferences) | 
| 86 | ->addConditionIsMissed($isMissed); | 
| 87 | return $this->readResolvedList($query, $resolveReferences); | 
| 88 | } | 
| 89 | |
| 90 | public function readListWithAppointment($withAppointment = 1, $resolveReferences = 0) | 
| 91 | { | 
| 92 | $query = new Query\ProcessStatusArchived(Query\Base::SELECT); | 
| 93 | $query->addEntityMapping() | 
| 94 | ->addResolvedReferences($resolveReferences) | 
| 95 | ->addConditionWithAppointment($withAppointment); | 
| 96 | return $this->readResolvedList($query, $resolveReferences); | 
| 97 | } | 
| 98 | |
| 99 | protected function readResolvedList($query, $resolveReferences) | 
| 100 | { | 
| 101 | $processList = new Collection(); | 
| 102 | $resultList = $this->fetchList($query, new Entity()); | 
| 103 | if (count($resultList)) { | 
| 104 | foreach ($resultList as $entity) { | 
| 105 | if (0 == $resolveReferences) { | 
| 106 | $processList->addEntity($entity); | 
| 107 | } else { | 
| 108 | if ($entity instanceof Entity) { | 
| 109 | $entity = $this->readResolvedReferences($entity, $resolveReferences); | 
| 110 | $processList->addEntity($entity); | 
| 111 | } | 
| 112 | } | 
| 113 | } | 
| 114 | } | 
| 115 | return $processList; | 
| 116 | } | 
| 117 | |
| 118 | public function writeEntityFinished( | 
| 119 | \BO\Zmsentities\Process $process, | 
| 120 | \DateTimeInterface $now, | 
| 121 | bool $calculateStatistic = false, | 
| 122 | ?\BO\Zmsentities\Useraccount $useraccount = null | 
| 123 | ) { | 
| 124 | $process = $this->updateEntity( | 
| 125 | $process, | 
| 126 | $now, | 
| 127 | 1, | 
| 128 | null, | 
| 129 | $useraccount | 
| 130 | ); | 
| 131 | $archived = null; | 
| 132 | if ($this->writeBlockedEntity($process)) { | 
| 133 | $archived = $this->writeNewArchivedProcess($process, $now, 0, $calculateStatistic); | 
| 134 | } | 
| 135 | // update xRequest entry and update process id as well as archived id | 
| 136 | if ($archived) { | 
| 137 | $this->writeXRequestsArchived($process->id, $archived->archiveId); | 
| 138 | } | 
| 139 | return $archived; | 
| 140 | } | 
| 141 | |
| 142 | /** | 
| 143 | * write an archived process to statistic table | 
| 144 | * | 
| 145 | */ | 
| 146 | public function writeArchivedProcessToStatistic( | 
| 147 | Entity $process, | 
| 148 | $requestId, | 
| 149 | $clusterId, | 
| 150 | $providerId, | 
| 151 | $departmentId, | 
| 152 | $organisationId, | 
| 153 | $ownerId, | 
| 154 | $dateTime, | 
| 155 | $processingTime | 
| 156 | ) { | 
| 157 | return $this->perform( | 
| 158 | Query\ProcessStatusArchived::QUERY_INSERT_IN_STATISTIC, | 
| 159 | [ | 
| 160 | 'archiveId' => $process->archiveId, | 
| 161 | 'scopeId' => $process->scope->getId(), | 
| 162 | 'clusterId' => $clusterId, | 
| 163 | 'providerId' => $providerId, | 
| 164 | 'departmentId' => $departmentId, | 
| 165 | 'organisationId' => $organisationId, | 
| 166 | 'ownerId' => $ownerId, | 
| 167 | 'date' => $process->getFirstAppointment()->toDateTime()->format('Y-m-d'), | 
| 168 | 'withAppointment' => ($process->toQueue($dateTime)->withAppointment) ? 1 : 0, | 
| 169 | 'requestId' => $requestId, | 
| 170 | 'processingTime' => $processingTime | 
| 171 | ] | 
| 172 | ); | 
| 173 | } | 
| 174 | |
| 175 | /** | 
| 176 | * write a new archived process to DB | 
| 177 | * | 
| 178 | */ | 
| 179 | public function writeNewArchivedProcess( | 
| 180 | \BO\Zmsentities\Process $process, | 
| 181 | \DateTimeInterface $now, | 
| 182 | $resolveReferences = 0, | 
| 183 | bool $calculateStatistic = false | 
| 184 | ) { | 
| 185 | $query = new Query\ProcessStatusArchivedToday(Query\Base::INSERT); | 
| 186 | $query->addValuesNewArchive($process, $now); | 
| 187 | $this->writeItem($query); | 
| 188 | |
| 189 | $query = new Query\ProcessStatusArchived(Query\Base::INSERT); | 
| 190 | $query->addValuesNewArchive($process, $now); | 
| 191 | $this->writeItem($query); | 
| 192 | |
| 193 | $archiveId = $this->getWriter()->lastInsertId(); | 
| 194 | Log::writeProcessLog( | 
| 195 | "ARCHIVE (Archive::writeNewArchivedProcess) $archiveId -> $process ", | 
| 196 | Log::ACTION_ARCHIVED, | 
| 197 | $process | 
| 198 | ); | 
| 199 | |
| 200 | if ($calculateStatistic) { | 
| 201 | (new ExchangeWaitingscope())->updateWaitingStatistics($process, $now); | 
| 202 | } | 
| 203 | |
| 204 | return $this->readArchivedEntity($archiveId, $resolveReferences); | 
| 205 | } | 
| 206 | |
| 207 | protected function writeXRequestsArchived($processId, $archiveId) | 
| 208 | { | 
| 209 | $query = new Query\XRequest(Query\Base::UPDATE); | 
| 210 | $query->addConditionProcessId($processId); | 
| 211 | $query->addValues([ | 
| 212 | 'BuergerID' => 0, | 
| 213 | 'BuergerarchivID' => $archiveId | 
| 214 | ]); | 
| 215 | $this->writeItem($query); | 
| 216 | } | 
| 217 | |
| 218 | /** | 
| 219 | * Anonymizes names in the buergerarchiv table for entries older than a specified timespan. | 
| 220 | * | 
| 221 | * @param \DateTimeInterface $dateTime The date before which records should be anonymized. | 
| 222 | * @return bool Indicates whether the update operation was successful. | 
| 223 | */ | 
| 224 | public function anonymizeNames(\DateTimeInterface $dateTime) | 
| 225 | { | 
| 226 | $query = new Query\ProcessStatusArchived(Query\Base::UPDATE); | 
| 227 | $query->addConditionOlderThanDate($dateTime); | 
| 228 | $query->addValues([ | 
| 229 | 'name' => 'ANONYMIZED' | 
| 230 | ]); | 
| 231 | |
| 232 | return $this->writeItem($query); | 
| 233 | } | 
| 234 | } |