Elgg  Version 6.2
UpdateMetastringBoolDatabaseValue.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Upgrades;
4 
11 
13 
17  public function getVersion(): int {
18  return 2025060201;
19  }
20 
24  public function shouldBeSkipped(): bool {
25  return empty($this->countItems());
26  }
27 
31  public function needsIncrementOffset(): bool {
32  return false;
33  }
34 
38  public function countItems(): int {
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 
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 
61  public function run(Result $result, $offset): Result {
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 
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 }
static table(string $table)
Returns a QueryBuilder for updating data in a given table.
Definition: Update.php:17
const ELGG_VALUE_INTEGER
Value types.
Definition: constants.php:111
if(empty($count)) $offset
Definition: pagination.php:26
addSuccesses(int $num=1)
Set an item (or items) as successfully upgraded.
Definition: Result.php:73
$count
Definition: ban.php:24
Result of a single BatchUpgrade run.
Definition: Result.php:10
const ELGG_VALUE_STRING
Definition: constants.php:112
$metadata
Output annotation metadata.
Definition: metadata.php:9
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
static fromTable(string $table,?string $alias=null)
Returns a QueryBuilder for selecting data from a given table.
Definition: Select.php:18
System upgrades are executed synchronously at system upgrade.