1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Elgg\Upgrades; |
4
|
|
|
|
5
|
|
|
use Elgg\Database\AnnotationsTable; |
6
|
|
|
use Elgg\Database\MetadataTable; |
7
|
|
|
use Elgg\Database\Select; |
8
|
|
|
use Elgg\Database\Update; |
9
|
|
|
use Elgg\Upgrade\Result; |
10
|
|
|
use Elgg\Upgrade\SystemUpgrade; |
11
|
|
|
|
12
|
|
|
class UpdateMetastringBoolDatabaseValue extends SystemUpgrade { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
7 |
|
public function getVersion(): int { |
18
|
7 |
|
return 2025060201; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function shouldBeSkipped(): bool { |
25
|
|
|
return empty($this->countItems()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function needsIncrementOffset(): bool { |
32
|
|
|
return false; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function countItems(): int { |
39
|
|
|
$annotations = Select::fromTable(AnnotationsTable::TABLE_NAME); |
40
|
|
|
$annotations->select('count(*) as total') |
41
|
|
|
->where($annotations->compare('value', '=', '', ELGG_VALUE_STRING)) |
42
|
|
|
->andWhere($annotations->compare('value_type', '=', 'bool', ELGG_VALUE_STRING)); |
43
|
|
|
|
44
|
|
|
$metadata = Select::fromTable(MetadataTable::TABLE_NAME); |
45
|
|
|
$metadata->select('count(*) as total') |
46
|
|
|
->where($metadata->compare('value', '=', '', ELGG_VALUE_STRING)) |
47
|
|
|
->andWhere($metadata->compare('value_type', '=', 'bool', ELGG_VALUE_STRING)); |
48
|
|
|
|
49
|
|
|
$row = _elgg_services()->db->getDataRow($annotations); |
50
|
|
|
$count = (int) $row->total; |
51
|
|
|
|
52
|
|
|
$row = _elgg_services()->db->getDataRow($metadata); |
53
|
|
|
$count += (int) $row->total; |
54
|
|
|
|
55
|
|
|
return $count; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function run(Result $result, $offset): Result { |
62
|
|
|
$annotations = Update::table(AnnotationsTable::TABLE_NAME); |
63
|
|
|
$annotations->set('value', $annotations->param(0, ELGG_VALUE_INTEGER)) |
64
|
|
|
->where($annotations->compare('value', '=', '', ELGG_VALUE_STRING)) |
65
|
|
|
->andWhere($annotations->compare('value_type', '=', 'bool', ELGG_VALUE_STRING)); |
66
|
|
|
|
67
|
|
|
$result->addSuccesses(_elgg_services()->db->updateData($annotations, true)); |
68
|
|
|
|
69
|
|
|
$metadata = Update::table(MetadataTable::TABLE_NAME); |
70
|
|
|
$metadata->set('value', $metadata->param(0, ELGG_VALUE_INTEGER)) |
71
|
|
|
->where($metadata->compare('value', '=', '', ELGG_VALUE_STRING)) |
72
|
|
|
->andWhere($metadata->compare('value_type', '=', 'bool', ELGG_VALUE_STRING)); |
73
|
|
|
|
74
|
|
|
$result->addSuccesses(_elgg_services()->db->updateData($metadata, true)); |
75
|
|
|
|
76
|
|
|
return $result; |
77
|
|
|
} |
78
|
|
|
} |