Elgg  Version 6.3
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 {
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 
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 }
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Definition: actions.php:73
$count
Definition: ban.php:24
Interfaces with the database to perform CRUD operations on annotations.
This class interfaces with the database to perform CRUD operations on metadata.
Query builder for fetching data from the database.
Definition: Select.php:8
Query builder for updating data in the database.
Definition: Update.php:8
Result of a single BatchUpgrade run.
Definition: Result.php:10
System upgrades are executed synchronously at system upgrade.
needsIncrementOffset()
{Should the run() method receive an offset representing all processed items?If true,...
run(Result $result, $offset)
{Runs upgrade on a single batch of items.If countItems() returns Batch::UNKNOWN_COUNT,...
shouldBeSkipped()
{Should this upgrade be skipped?If true, the upgrade will not be performed and cannot be accessed lat...
getVersion()
{Version of the upgrade.This tells the date when the upgrade was added. It consists of eight digits a...
countItems()
{The total number of items to process during the upgrade.If unknown, Batch::UNKNOWN_COUNT should be r...
const ELGG_VALUE_STRING
Definition: constants.php:112
const ELGG_VALUE_INTEGER
Value types.
Definition: constants.php:111
_elgg_services()
Get the global service provider.
Definition: elgglib.php:337
if(empty($count)) $offset
Definition: pagination.php:26
$metadata
Output annotation metadata.
Definition: metadata.php:9