-
Notifications
You must be signed in to change notification settings - Fork 4
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 #120 from NetCommons3/issue-Netcommons3/Netcommons…
…3#754 Issue NetCommons3/NetCommons3#754
- Loading branch information
Showing
3 changed files
with
92 additions
and
135 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
Config/Migration/1499309604_delete_publishable_permission.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,92 @@ | ||
<?php | ||
/** | ||
* DeletePublishablePermission | ||
* | ||
*/ | ||
|
||
/** | ||
* DeletePublishablePermission | ||
* | ||
*/ | ||
class DeletePublishablePermission extends CakeMigration { | ||
|
||
/** | ||
* Migration description | ||
* | ||
* @var string | ||
*/ | ||
public $description = 'delete_publishable_permission'; | ||
|
||
/** | ||
* Actions to be performed | ||
* | ||
* @var array $migration | ||
*/ | ||
public $migration = array( | ||
'up' => array(), | ||
'down' => array(), | ||
); | ||
|
||
/** | ||
* Before migration callback | ||
* | ||
* @param string $direction Direction of migration process (up or down) | ||
* @return bool Should process continue | ||
*/ | ||
public function before($direction) { | ||
return true; | ||
} | ||
|
||
/** | ||
* After migration callback | ||
* | ||
* @param string $direction Direction of migration process (up or down) | ||
* @return bool Should process continue | ||
*/ | ||
public function after($direction) { | ||
if ($direction === 'down') { | ||
return true; | ||
} | ||
|
||
/* @var $DefaultRolePermission AppModel */ | ||
/* @var $RolesRoom AppModel */ | ||
/* @var $Block AppModel */ | ||
$DefaultRolePermission = $this->generateModel('DefaultRolePermission'); | ||
$RolesRoom = $this->generateModel('RolesRoom'); | ||
$Block = $this->generateModel('BlockRolePermission'); | ||
|
||
$query = [ | ||
'fields' => 'role_key', | ||
'conditions' => [ | ||
'permission' => 'content_comment_publishable', | ||
'fixed' => '1' | ||
], | ||
'recursive' => -1 | ||
]; | ||
$roleKeyList = $DefaultRolePermission->find('list', $query); | ||
|
||
$query = [ | ||
'fields' => 'id', | ||
'conditions' => [ | ||
'role_key' => $roleKeyList, | ||
], | ||
'recursive' => -1 | ||
]; | ||
$roleRoomIdList = $RolesRoom->find('list', $query); | ||
|
||
$conditions = [ | ||
'OR' => [ | ||
'permission' => 'content_publishable', | ||
[ | ||
'permission' => 'content_comment_publishable', | ||
'roles_room_id' => $roleRoomIdList | ||
] | ||
] | ||
]; | ||
if (!$Block->deleteAll($conditions, false)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
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