-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Group MultiSelect Relation Fetch (#96)
* fix group multiselect data fetch, see #95 * fix formatting * add database reference * add deep object clean-up in tests
- Loading branch information
Showing
17 changed files
with
255 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace MembersBundle\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use MembersBundle\Adapter\Group\AbstractGroup; | ||
use Pimcore\Migrations\Migration\AbstractPimcoreMigration; | ||
use Pimcore\Model\DataObject; | ||
|
||
class Version20190508092938 extends AbstractPimcoreMigration | ||
{ | ||
/** | ||
* @return bool | ||
*/ | ||
public function doesSqlMigrations(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* @param Schema $schema | ||
*/ | ||
public function up(Schema $schema) | ||
{ | ||
$groupFound = false; | ||
|
||
$list = new DataObject\ClassDefinition\Listing(); | ||
$list = $list->load(); | ||
|
||
foreach ($list as $class) { | ||
if ($groupFound === true) { | ||
break; | ||
} | ||
|
||
if ($class->getParentClass() === sprintf('\%s', AbstractGroup::class)) { | ||
if (is_array($class->getFieldDefinitions())) { | ||
foreach ($class->getFieldDefinitions() as $fieldDefinition) { | ||
if ($fieldDefinition->getName() === 'roles') { | ||
if ($fieldDefinition instanceof DataObject\ClassDefinition\Data\Multiselect) { | ||
if ($fieldDefinition->getOptionsProviderClass() === '@MembersBundle\CoreExtension\Provider\RoleOptionsProvider') { | ||
// already a service. skip.... | ||
$this->writeMessage('RoleOptionsProvider already defined as service. skipping...'); | ||
$groupFound = true; | ||
|
||
break; | ||
} elseif ($fieldDefinition->getOptionsProviderClass() === 'MembersBundle\CoreExtension\Provider\RoleOptionsProvider') { | ||
$groupFound = true; | ||
$fieldDefinition->setOptionsProviderClass('@MembersBundle\CoreExtension\Provider\RoleOptionsProvider'); | ||
$this->writeMessage('Convert RoleOptionsProvider to symfony service...'); | ||
$class->save(); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ($groupFound === false) { | ||
$this->write( | ||
sprintf( | ||
'<error>No valid Members Group Class found. Please change "options provider class" of field "roles" to "%s" manually.</error>', | ||
'@MembersBundle\CoreExtension\Provider\RoleOptionsProvider' | ||
) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* @param Schema $schema | ||
*/ | ||
public function down(Schema $schema) | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/MembersBundle/Resources/config/services/options_provider.yml
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,11 @@ | ||
services: | ||
|
||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: true | ||
|
||
MembersBundle\CoreExtension\Provider\RoleOptionsProvider: | ||
arguments: | ||
$systemRoles: '%security.role_hierarchy.roles%' | ||
|
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
2 changes: 1 addition & 1 deletion
2
tests/_support/Util/VersionHelper.php → src/MembersBundle/Tool/VersionHelper.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace DachcomBundle\Test\Util; | ||
namespace MembersBundle\Tool; | ||
|
||
class VersionHelper | ||
{ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
namespace DachcomBundle\Test\Util; | ||
|
||
use MembersBundle\Tool\Install; | ||
use MembersBundle\Tool\VersionHelper; | ||
use Pimcore\Model\DataObject; | ||
use Pimcore\Tests\Util\TestHelper; | ||
|
||
class MembersHelper | ||
{ | ||
|
@@ -11,8 +14,20 @@ class MembersHelper | |
const DEFAULT_FEU_EMAIL = '[email protected]'; | ||
const DEFAULT_FEU_PASSWORD = 'default-password'; | ||
|
||
const DEFAULT_FEG_NAME = 'Default Group'; | ||
|
||
public static function cleanUp() | ||
{ | ||
TestHelper::cleanUp(); | ||
|
||
$objectList = new DataObject\Listing(); | ||
$objectList->setCondition('o_id != 1'); | ||
$objectList->setUnpublished(true); | ||
|
||
foreach ($objectList->getObjects() as $object) { | ||
$object->delete(); | ||
} | ||
|
||
$db = \Pimcore\Db::get(); | ||
$db->exec('TRUNCATE TABLE members_restrictions'); | ||
$db->exec('TRUNCATE TABLE members_group_relations'); | ||
|
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace DachcomBundle\Test\unit\Dao; | ||
|
||
use DachcomBundle\Test\Test\DachcomBundleTestCase; | ||
use DachcomBundle\Test\Util\MembersHelper; | ||
use Pimcore\Model\DataObject\MembersGroup; | ||
|
||
class GroupTest extends DachcomBundleTestCase | ||
{ | ||
/** | ||
* @throws \Exception | ||
*/ | ||
public function testGroupDaoEntity() | ||
{ | ||
$group = $this->createUserGroup('group-1', ['ROLE_MEMBERS_MODERATOR']); | ||
$storedGroup = MembersGroup::getById($group->getId(), true); | ||
|
||
$this->assertInstanceOf(MembersGroup::class, $group); | ||
$this->assertEquals(MembersHelper::DEFAULT_FEG_NAME, $storedGroup->getName()); | ||
$this->assertCount(1, $storedGroup->getRoles()); | ||
$this->assertEquals('ROLE_MEMBERS_MODERATOR', $storedGroup->getRoles()[0]); | ||
} | ||
} |
Oops, something went wrong.