Elgg  Version master
20171006111953_drop_sites_entity_table.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class DropSitesEntityTable extends AbstractMigration
6 {
10  public function up() {
11 
12  if (!$this->hasTable('sites_entity') || !$this->hasTable('metadata')) {
13  return;
14  }
15 
16  $prefix = $this->getAdapter()->getOption('table_prefix');
17  $rows = $this->fetchAll("
18  SELECT * FROM {$prefix}sites_entity
19  ");
20 
21  $cols = ['name', 'description', 'url'];
22 
23  foreach ($rows as $row) {
24  foreach ($cols as $col) {
25  // remove existing metadata... attributes are more important
26  $this->execute("
27  DELETE FROM {$prefix}metadata
28  WHERE entity_guid = {$row['guid']} AND
29  name = '{$col}'
30  ");
31 
32  $this->table('metadata')->insert([[
33  'entity_guid' => $row['guid'],
34  'name' => $col,
35  'value' => $row[$col],
36  'value_type' => 'text',
37  'owner_guid' => 0,
38  'access_id' => 2,
39  'time_created' => time(),
40  'enabled' => 'yes',
41  ]])->saveData();
42  }
43  }
44 
45  // all data migrated, so drop the table
46  $this->table('sites_entity')->drop()->save();
47  }
48 }
$rows
Definition: redis.php:25
up()
Move sites_entity attributes to metadata.