Files
Phraseanet/lib/Alchemy/Phrasea/Command/CreateCollection.php
Romain Neutron 420df7febd Merge branch '3.8'
Conflicts:
	lib/Alchemy/Phrasea/Command/CreateCollection.php
	lib/Alchemy/Phrasea/Controller/Admin/Databox.php
	lib/Alchemy/Phrasea/Controller/Root/Login.php
	lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php
	lib/Alchemy/Phrasea/Model/Entities/AuthFailure.php
	lib/Alchemy/Phrasea/Model/Entities/LazaretAttribute.php
	lib/Alchemy/Phrasea/Model/Entities/LazaretCheck.php
	lib/Alchemy/Phrasea/Model/Entities/SessionModule.php
	lib/Alchemy/Phrasea/Model/Entities/ValidationData.php
	lib/Alchemy/Phrasea/Model/Repositories/BasketRepository.php
	lib/conf.d/Doctrine/Entities.Session.dcm.yml
	lib/conf.d/Doctrine/Entities.StoryWZ.dcm.yml
	lib/conf.d/Doctrine/Entities.UsrList.dcm.yml
	lib/conf.d/Doctrine/Entities.UsrListEntry.dcm.yml
	lib/conf.d/Doctrine/Entities.UsrListOwner.dcm.yml
	lib/conf.d/Doctrine/Entities.ValidationSession.dcm.yml
	lib/conf.d/PhraseaFixture/Basket/LoadFiveBaskets.php
	tests/Alchemy/Tests/Phrasea/SearchEngine/SphinxSearchEngineTest.php
2013-12-03 21:19:20 +01:00

71 lines
2.5 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Core\Event\CollectionCreateEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CreateCollection extends Command
{
/**
* Constructor
*/
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('Creates a collection in Phraseanet')
->setHelp('')
->addArgument('databox_id', InputArgument::REQUIRED, 'The id of the databox where to create the collection', null)
->addArgument('collname', InputArgument::REQUIRED, 'The name of the new collection', null)
->addOption('base_id_rights', 'd', InputOption::VALUE_OPTIONAL, 'Duplicate rights from another collection', null);
return $this;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$databox = $this->container['phraseanet.appbox']
->get_databox((int) $input->getArgument('databox_id'));
$new_collection = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], $input->getArgument('collname'));
if ($new_collection && $input->getOption('base_id_rights')) {
$query = new \User_Query($this->container);
$total = $query->on_base_ids([$input->getOption('base_id_rights')])->get_total();
$n = 0;
while ($n < $total) {
$results = $query->limit($n, 40)->execute()->get_results();
foreach ($results as $user) {
$this->container['acl']->get($user)->duplicate_right_from_bas($input->getOption('base_id_rights'), $new_collection->get_base_id());
}
$n+=40;
}
}
$app = $this->container;
$this->container['manipulator.acl']->resetAdminRights(array_map(function ($id) use ($app) {
return \User_Adapter::getInstance($id, $app);
}, array_keys(\User_Adapter::get_sys_admins($this->container))));
$this->container['dispatcher']->dispatch(PhraseaEvents::COLLECTION_CREATE, new CollectionCreateEvent($new_collection));
}
}