|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Drupal\qa\Plugin\QaCheck\References; |
|
6
|
|
|
|
|
7
|
|
|
use Drupal\Core\Database\Connection; |
|
8
|
|
|
use Drupal\qa\Pass; |
|
9
|
|
|
use Drupal\qa\Plugin\QaCheckBase; |
|
10
|
|
|
use Drupal\qa\Plugin\QaCheckInterface; |
|
11
|
|
|
use Drupal\qa\Result; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* TaxonomyIndex checks for broken taxonomy_index references. |
|
16
|
|
|
* |
|
17
|
|
|
* It is not a generic reference integrity check, just a consistency chec for |
|
18
|
|
|
* the taxonomy_index table. |
|
19
|
|
|
* |
|
20
|
|
|
* @QaCheck( |
|
21
|
|
|
* id = "references.taxonomy_index", |
|
22
|
|
|
* label = @Translation("Taxonomy index"), |
|
23
|
|
|
* details = @Translation("This check finds references in the taxonomy_index. These have to be repaired, as they can cause incorrect content displays."), |
|
24
|
|
|
* usesBatch = false, |
|
25
|
|
|
* steps = 1, |
|
26
|
|
|
* ) |
|
27
|
|
|
*/ |
|
28
|
|
|
class TaxonomyIndex extends QaCheckBase implements QaCheckInterface { |
|
29
|
|
|
|
|
30
|
|
|
const NAME = "references." . self::TABLE; |
|
31
|
|
|
|
|
32
|
|
|
const TABLE = 'taxonomy_index'; |
|
33
|
|
|
|
|
34
|
|
|
const KEY_NODES = 'missingNodes'; |
|
35
|
|
|
const KEY_TERMS = 'missingTerms'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The database service. |
|
39
|
|
|
* |
|
40
|
|
|
* @var \Drupal\Core\Database\Connection |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $db; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* ContentOrphans constructor. |
|
46
|
|
|
* |
|
47
|
|
|
* @param array $configuration |
|
48
|
|
|
* The plugin configuration. |
|
49
|
|
|
* @param string $id |
|
50
|
|
|
* The plugin ID. |
|
51
|
|
|
* @param array $definition |
|
52
|
|
|
* The plugin definition. |
|
53
|
|
|
* @param \Drupal\qa\Plugin\QaCheck\References\Connection $db |
|
|
|
|
|
|
54
|
|
|
* The database service. |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct( |
|
57
|
|
|
array $configuration, |
|
58
|
|
|
string $id, |
|
59
|
|
|
array $definition, |
|
60
|
|
|
Connection $db |
|
61
|
|
|
) { |
|
62
|
|
|
parent::__construct($configuration, $id, $definition); |
|
63
|
|
|
$this->db = $db; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public static function create( |
|
70
|
|
|
ContainerInterface $container, |
|
71
|
|
|
array $configuration, |
|
72
|
|
|
$id, |
|
73
|
|
|
$definition |
|
74
|
|
|
) { |
|
75
|
|
|
$db = $container->get('database'); |
|
76
|
|
|
return new static($configuration, $id, $definition, $db); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Locate {taxonomy_index} entries linking to a missing term or node. |
|
81
|
|
|
* |
|
82
|
|
|
* @return \Drupal\qa\Result |
|
83
|
|
|
*/ |
|
84
|
|
|
public function checkIndex(): Result { |
|
85
|
|
|
$sql = <<<SQL |
|
86
|
|
|
SELECT ti.tid AS indexTid,ti.nid AS indexNid, |
|
87
|
|
|
nfd.nid, |
|
88
|
|
|
tfd.tid |
|
89
|
|
|
FROM {taxonomy_index} ti |
|
90
|
|
|
LEFT JOIN {taxonomy_term_field_data} tfd ON ti.tid = tfd.tid |
|
91
|
|
|
LEFT JOIN {node_field_data} nfd ON ti.nid = nfd.nid |
|
92
|
|
|
WHERE tfd.tid IS NULL |
|
93
|
|
|
OR nfd.nid IS NULL |
|
94
|
|
|
SQL; |
|
95
|
|
|
// No node access: we are scanning the whole database for a fully privileged user. |
|
96
|
|
|
$q = $this->db->query($sql); |
|
97
|
|
|
$missing = [ |
|
98
|
|
|
self::KEY_TERMS => [], |
|
99
|
|
|
self::KEY_NODES => [], |
|
100
|
|
|
]; |
|
101
|
|
|
foreach ($q->fetchAll() as $o) { |
|
102
|
|
|
if (is_null($o->tid)) { |
|
103
|
|
|
$missing[self::KEY_TERMS][] = [ |
|
104
|
|
|
'nid' => (int) $o->indexNid, |
|
105
|
|
|
'missingTid' => (int) $o->indexTid, |
|
106
|
|
|
]; |
|
107
|
|
|
} |
|
108
|
|
|
if (is_null($o->nid)) { |
|
109
|
|
|
$missing[self::KEY_NODES][] = [ |
|
110
|
|
|
'tid' => (int) $o->indexTid, |
|
111
|
|
|
'missingNid' => (int) $o->indexNid, |
|
112
|
|
|
]; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
sort($missing[self::KEY_TERMS]); |
|
116
|
|
|
sort($missing[self::KEY_NODES]); |
|
117
|
|
|
if (empty($missing[self::KEY_TERMS])) { |
|
118
|
|
|
unset($missing[self::KEY_TERMS]); |
|
119
|
|
|
} |
|
120
|
|
|
if (empty($missing[self::KEY_NODES])) { |
|
121
|
|
|
unset($missing[self::KEY_NODES]); |
|
122
|
|
|
} |
|
123
|
|
|
return new Result(self::TABLE, empty($missing), $missing); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* {@inheritdoc} |
|
128
|
|
|
*/ |
|
129
|
|
|
public function run(): Pass { |
|
130
|
|
|
$pass = parent::run(); |
|
131
|
|
|
$pass->record($this->checkIndex()); |
|
132
|
|
|
$pass->life->end(); |
|
133
|
|
|
return $pass; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths