ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Integrity.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
26{
27 public function __construct(
28 private ilDBInterface $database
29 ) {
30 }
31
50 public function check(Definition $definition): Result
51 {
52 $on = [];
53 $where = [];
54 // $definition->associations() always returns a non empty array
55 foreach ($definition->associations() as $association) {
56 $on[] = sprintf('%s = %s', $association->field()->fieldName(), $association->referenceField()->fieldName());
57 $where[] = sprintf('%s IS NULL', $association->referenceField()->fieldName());
58 foreach ($definition->ignoreValues() as $value_to_ignore) {
59 $where[] = sprintf('%s %s', $association->field()->fieldName(), $value_to_ignore);
60 }
61 }
62
63 $result = $this->database->query(sprintf(
64 'SELECT COUNT(1) as violations FROM %s LEFT JOIN %s ON %s WHERE %s',
65 $definition->tableName(),
66 $definition->referenceTableName(),
67 implode(' AND ', $on),
68 implode(' AND ', $where),
69 ));
70
71 $result = $this->database->fetchAssoc($result);
72
73 return new Result((int) $result['violations']);
74 }
75}
check(Definition $definition)
Example: $violations = $this->check(new Definition([ new Association(new Field('mail',...
Definition: Integrity.php:50
__construct(private ilDBInterface $database)
Definition: Integrity.php:27
Interface ilDBInterface.