Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11254 from jdalsem/drop-group-subtable
Drop group subtable
- Loading branch information
Showing
15 changed files
with
120 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
engine/schema/migrations/20171006131622_drop_groups_entity_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class DropGroupsEntityTable extends AbstractMigration | ||
{ | ||
/** | ||
* Move groups_entity attributes to metadata | ||
*/ | ||
public function up() { | ||
|
||
if (!$this->hasTable('groups_entity') || !$this->hasTable('metadata')) { | ||
return; | ||
} | ||
|
||
$prefix = $this->getAdapter()->getOption('table_prefix'); | ||
$cols = ['name', 'description']; | ||
|
||
$groups_query = "SELECT * FROM {$prefix}groups_entity LIMIT 25"; | ||
while ($rows = $this->fetchAll($groups_query)) { | ||
foreach ($rows as $row) { | ||
foreach ($cols as $col) { | ||
|
||
// remove existing metadata... attributes are more important | ||
$this->execute(" | ||
DELETE FROM {$prefix}metadata | ||
WHERE entity_guid = {$row['guid']} AND | ||
name = '{$col}' | ||
"); | ||
|
||
$this->insert('metadata', [ | ||
'entity_guid' => $row['guid'], | ||
'name' => $col, | ||
'value' => $row[$col], | ||
'value_type' => 'text', | ||
'owner_guid' => 0, | ||
'access_id' => 2, | ||
'time_created' => time(), | ||
'enabled' => 'yes', | ||
]); | ||
} | ||
|
||
// remove from groups so it does not get processed again in the next while loop | ||
$this->execute(" | ||
DELETE FROM {$prefix}groups_entity | ||
WHERE guid = {$row['guid']} | ||
"); | ||
} | ||
} | ||
|
||
// all data migrated, so drop the table | ||
$this->dropTable('groups_entity'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
<?php | ||
|
||
/** | ||
* Renders a list of groups ordered alphabetically | ||
*/ | ||
$dbprefix = elgg_get_config('dbprefix'); | ||
echo elgg_list_entities([ | ||
echo elgg_list_entities_from_metadata([ | ||
'type' => 'group', | ||
'joins' => ["JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"], | ||
'order_by' => 'ge.name', | ||
'order_by_metadata' => [ | ||
'name' => 'name', | ||
'direction' => 'ASC', | ||
], | ||
'full_view' => false, | ||
'no_results' => elgg_echo('groups:none'), | ||
'distinct' => false, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,4 @@ | |
'type' => 'group', | ||
'full_view' => false, | ||
'no_results' => elgg_echo('groups:none'), | ||
'distinct' => false, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters