Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /** * Passbolt ~ Open source password manager for teams * Copyright (c) Passbolt S..

Decoded Output download

<?php
/**
 * Passbolt ~ Open source password manager for teams
 * Copyright (c) Passbolt SA (https://www.passbolt.com)
 *
 * Licensed under GNU Affero General Public License version 3 of the or any later version.
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Passbolt SA (https://www.passbolt.com)
 * @license       https://opensource.org/licenses/AGPL-3.0 AGPL License
 * @link          https://www.passbolt.com Passbolt(tm)
 * @since         2.13.0
 */

use App\Service\Permissions\PermissionsGetUsersIdsHavingAccessToService;
use App\Utility\UuidFactory;
use Cake\I18n\FrozenTime;
use Cake\ORM\TableRegistry;
use Migrations\AbstractMigration;
use Passbolt\Folders\Model\Entity\FoldersRelation;

class V2130AddResourcesFoldersRelations extends AbstractMigration
{
    public function up()
    {
        $getUsersIdsHavingAccessToServices = new PermissionsGetUsersIdsHavingAccessToService();
        $resourcesTable = TableRegistry::getTableLocator()->get('Resources');
        $resources = $resourcesTable->find()->where(['deleted' => false])->toArray();

        foreach($resources as $resource) {
            $usersIdsHavingAccessTo = $getUsersIdsHavingAccessToServices->getUsersIdsHavingAccessTo($resource->id);
            $this->addResourceFoldersRelations($resource->id, $usersIdsHavingAccessTo);
        }
    }

    private function addResourceFoldersRelations(string $resourceId, array $usersIdsHavingAccessTo)
    {
        $foldersRelationsTable = $this->table('folders_relations');
        $data = [];

        foreach ($usersIdsHavingAccessTo as $userId) {
            $data[] = [
                'id' => UuidFactory::uuid(),
                'foreign_model' => FoldersRelation::FOREIGN_MODEL_RESOURCE,
                'foreign_id' => $resourceId,
                'user_id' => $userId,
                'folder_parent_id' => null,
                'created' => (new FrozenTime())->toDateTimeString(),
                'modified' => (new FrozenTime())->toDateTimeString(),
            ];
        }

        $foldersRelationsTable->insert($data)->saveData();
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php
/**
 * Passbolt ~ Open source password manager for teams
 * Copyright (c) Passbolt SA (https://www.passbolt.com)
 *
 * Licensed under GNU Affero General Public License version 3 of the or any later version.
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Passbolt SA (https://www.passbolt.com)
 * @license       https://opensource.org/licenses/AGPL-3.0 AGPL License
 * @link          https://www.passbolt.com Passbolt(tm)
 * @since         2.13.0
 */

use App\Service\Permissions\PermissionsGetUsersIdsHavingAccessToService;
use App\Utility\UuidFactory;
use Cake\I18n\FrozenTime;
use Cake\ORM\TableRegistry;
use Migrations\AbstractMigration;
use Passbolt\Folders\Model\Entity\FoldersRelation;

class V2130AddResourcesFoldersRelations extends AbstractMigration
{
    public function up()
    {
        $getUsersIdsHavingAccessToServices = new PermissionsGetUsersIdsHavingAccessToService();
        $resourcesTable = TableRegistry::getTableLocator()->get('Resources');
        $resources = $resourcesTable->find()->where(['deleted' => false])->toArray();

        foreach($resources as $resource) {
            $usersIdsHavingAccessTo = $getUsersIdsHavingAccessToServices->getUsersIdsHavingAccessTo($resource->id);
            $this->addResourceFoldersRelations($resource->id, $usersIdsHavingAccessTo);
        }
    }

    private function addResourceFoldersRelations(string $resourceId, array $usersIdsHavingAccessTo)
    {
        $foldersRelationsTable = $this->table('folders_relations');
        $data = [];

        foreach ($usersIdsHavingAccessTo as $userId) {
            $data[] = [
                'id' => UuidFactory::uuid(),
                'foreign_model' => FoldersRelation::FOREIGN_MODEL_RESOURCE,
                'foreign_id' => $resourceId,
                'user_id' => $userId,
                'folder_parent_id' => null,
                'created' => (new FrozenTime())->toDateTimeString(),
                'modified' => (new FrozenTime())->toDateTimeString(),
            ];
        }

        $foldersRelationsTable->insert($data)->saveData();
    }
}

Function Calls

None

Variables

None

Stats

MD5 fcf816514e7f26a8aa17f2e3a93ee2f1
Eval Count 0
Decode Time 101 ms