-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
244 additions
and
42 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
59 changes: 59 additions & 0 deletions
59
engine/schema/migrations/20171110154113_create_friends_access_collections.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,59 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CreateFriendsAccessCollections extends AbstractMigration { | ||
public function up() { | ||
if (!$this->hasTable('entities') || !$this->hasTable('access_collections') || !$this->hasTable('access_collection_membership')) { | ||
return; | ||
} | ||
|
||
$prefix = $this->getAdapter()->getOption('table_prefix'); | ||
|
||
$users_query = " | ||
SELECT e.* FROM {$prefix}entities e | ||
WHERE e.type = 'user' | ||
AND e.guid NOT IN ( | ||
SELECT ac.owner_guid FROM {$prefix}access_collections ac | ||
WHERE ac.owner_guid = e.guid | ||
AND ac.subtype = 'friends' | ||
) | ||
LIMIT 25 | ||
"; | ||
|
||
while ($users = $this->fetchAll($users_query)) { | ||
foreach ($users as $user) { | ||
// create access collection for user friends | ||
$this->insert('access_collections', [ | ||
'name' => 'friends', | ||
'owner_guid' => $user['guid'], | ||
'subtype' => 'friends', | ||
]); | ||
|
||
// retrieve just created acl | ||
$access_collection_query = " | ||
SELECT * FROM {$prefix}access_collections | ||
WHERE owner_guid = {$user['guid']} | ||
AND subtype = 'friends' | ||
"; | ||
|
||
$acl = $this->fetchRow($access_collection_query); | ||
|
||
// get users friends | ||
$friends_query = " | ||
SELECT guid_two AS guid FROM {$prefix}entity_relationships | ||
WHERE guid_one = {$user['guid']} | ||
AND relationship = 'friend' | ||
"; | ||
$friends = $this->fetchAll($friends_query); | ||
foreach ($friends as $friend) { | ||
// add friend to user access collection | ||
$this->insert('access_collection_membership', [ | ||
'access_collection_id' => $acl['id'], | ||
'user_guid' => $friend['guid'], | ||
]); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.