mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Add collection:create command
This commit is contained in:
@@ -22,6 +22,7 @@ use Alchemy\Phrasea\Command\UpgradeDBDatas;
|
|||||||
use Alchemy\Phrasea\Command\RescanTechnicalDatas;
|
use Alchemy\Phrasea\Command\RescanTechnicalDatas;
|
||||||
use Alchemy\Phrasea\Command\BuildMissingSubdefs;
|
use Alchemy\Phrasea\Command\BuildMissingSubdefs;
|
||||||
use Alchemy\Phrasea\Command\RecordAdd;
|
use Alchemy\Phrasea\Command\RecordAdd;
|
||||||
|
use Alchemy\Phrasea\Command\CreateCollection;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
@@ -89,6 +90,8 @@ try {
|
|||||||
$app->add(new \module_console_fieldsRename('fields:rename'));
|
$app->add(new \module_console_fieldsRename('fields:rename'));
|
||||||
$app->add(new \module_console_fieldsMerge('fields:merge'));
|
$app->add(new \module_console_fieldsMerge('fields:merge'));
|
||||||
|
|
||||||
|
$app->add(new CreateCollection('collection:create'));
|
||||||
|
|
||||||
$app->add(new RecordAdd('records:add'));
|
$app->add(new RecordAdd('records:add'));
|
||||||
$app->add(new RescanTechnicalDatas('records:rescan-technical-datas'));
|
$app->add(new RescanTechnicalDatas('records:rescan-technical-datas'));
|
||||||
$app->add(new BuildMissingSubdefs('records:build-missing-subdefs'));
|
$app->add(new BuildMissingSubdefs('records:build-missing-subdefs'));
|
||||||
|
83
lib/Alchemy/Phrasea/Command/CreateCollection.php
Normal file
83
lib/Alchemy/Phrasea/Command/CreateCollection.php
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2012 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\Border\File;
|
||||||
|
use Alchemy\Phrasea\Border\Manager;
|
||||||
|
use Entities\LazaretFile;
|
||||||
|
use Entities\LazaretSession;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a collection Command
|
||||||
|
*
|
||||||
|
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||||
|
* @link www.phraseanet.com
|
||||||
|
*/
|
||||||
|
class CreateCollection extends Command
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public function __construct($name = null)
|
||||||
|
{
|
||||||
|
parent::__construct($name);
|
||||||
|
|
||||||
|
$this->setDescription('Create 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function requireSetup()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$core = \bootstrap::getCore();
|
||||||
|
|
||||||
|
$appbox = \appbox::get_instance($core);
|
||||||
|
$databox = $appbox->get_databox((int) $input->getArgument('databox_id'));
|
||||||
|
|
||||||
|
$new_collection = \collection::create($databox, $appbox, $input->getArgument('collname'));
|
||||||
|
|
||||||
|
if ($new_collection && $input->getOption('duplicate_rights_from_base_id')) {
|
||||||
|
|
||||||
|
$query = new \User_Query($appbox);
|
||||||
|
$total = $query->on_base_ids(array($input->getOption('duplicate_rights_from_base_id')))->get_total();
|
||||||
|
|
||||||
|
$n = 0;
|
||||||
|
while ($n < $total) {
|
||||||
|
$results = $query->limit($n, 40)->execute()->get_results();
|
||||||
|
foreach ($results as $user) {
|
||||||
|
$user->ACL()->duplicate_right_from_bas($input->getOption('duplicate_rights_from_base_id'), $new_collection->get_base_id());
|
||||||
|
}
|
||||||
|
$n+=40;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
User_Adapter::reset_sys_admins_rights();
|
||||||
|
}
|
||||||
|
}
|
@@ -22,8 +22,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
|||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rescan Technical Datas command : Rescan all records of all databases and
|
* Create a record command
|
||||||
* rescan technical datas.
|
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||||
* @link www.phraseanet.com
|
* @link www.phraseanet.com
|
||||||
|
@@ -487,7 +487,7 @@ class collection implements cache_cacheableInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create(databox $databox, appbox $appbox, $name, user_adapter $user)
|
public static function create(databox $databox, appbox $appbox, $name, User_Adapter $user = null)
|
||||||
{
|
{
|
||||||
$sbas_id = $databox->get_sbas_id();
|
$sbas_id = $databox->get_sbas_id();
|
||||||
$connbas = $databox->get_connection();
|
$connbas = $databox->get_connection();
|
||||||
@@ -533,9 +533,11 @@ class collection implements cache_cacheableInterface
|
|||||||
cache_databox::update($sbas_id, 'structure');
|
cache_databox::update($sbas_id, 'structure');
|
||||||
|
|
||||||
phrasea::reset_baseDatas();
|
phrasea::reset_baseDatas();
|
||||||
self::set_admin($new_bas, $user);
|
|
||||||
|
|
||||||
|
if (null !== $user) {
|
||||||
|
self::set_admin($new_bas, $user);
|
||||||
$appbox->get_session()->renew_phrasea_session();
|
$appbox->get_session()->renew_phrasea_session();
|
||||||
|
}
|
||||||
|
|
||||||
return self::get_from_coll_id($databox, $new_id);
|
return self::get_from_coll_id($databox, $new_id);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user