mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 13:03:20 +00:00
change : removed "/setmetadatas" from route, the http verb "PATCH" on "record" entity is ok
fix : unknown field now throws exception (no more erase all...) add : set "base_id":x to change collection cleanup : removed unused parm to recordadapter::move_to_collection()
This commit is contained in:
@@ -2093,7 +2093,7 @@ class V1Controller extends Controller
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$collection = \collection::getByBaseId($this->app, $request->get('base_id'));
|
$collection = \collection::getByBaseId($this->app, $request->get('base_id'));
|
||||||
$record->move_to_collection($collection, $this->getApplicationBox());
|
$record->move_to_collection($collection);
|
||||||
|
|
||||||
return Result::create($request, ["record" => $this->listRecord($request, $record)])->createResponse();
|
return Result::create($request, ["record" => $this->listRecord($request, $record)])->createResponse();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@@ -17,7 +17,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
|
||||||
class V3MetadatasController extends Controller
|
class V3RecordController extends Controller
|
||||||
{
|
{
|
||||||
use JsonBodyAware;
|
use JsonBodyAware;
|
||||||
use DispatcherAware;
|
use DispatcherAware;
|
||||||
@@ -32,7 +32,7 @@ class V3MetadatasController extends Controller
|
|||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function setmetadatasAction(Request $request, $databox_id, $record_id)
|
public function indexAction_patch(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
$struct = $this->findDataboxById($databox_id)->get_meta_structure();
|
$struct = $this->findDataboxById($databox_id)->get_meta_structure();
|
||||||
$record = $this->findDataboxById($databox_id)->get_record($record_id);
|
$record = $this->findDataboxById($databox_id)->get_record($record_id);
|
||||||
@@ -59,7 +59,10 @@ class V3MetadatasController extends Controller
|
|||||||
}
|
}
|
||||||
// do sb ops
|
// do sb ops
|
||||||
if (is_array($b->status)) {
|
if (is_array($b->status)) {
|
||||||
$debug['sb_ops'] = $this->do_status($struct, $record, $b->status);
|
$debug['sb_ops'] = $this->do_status($record, $b->status);
|
||||||
|
}
|
||||||
|
if(!is_null($b->base_id)) {
|
||||||
|
$debug['coll_ops'] = $this->do_collection($record, $b->base_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
@@ -77,13 +80,21 @@ class V3MetadatasController extends Controller
|
|||||||
return Result::create($request, $ret)->createResponse();
|
return Result::create($request, $ret)->createResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param record_adapter $record
|
||||||
|
* @param $base_id
|
||||||
|
*/
|
||||||
|
private function do_collection(record_adapter $record, $base_id)
|
||||||
|
{
|
||||||
|
$record->move_to_collection($this->getApplicationBox()->get_collection($base_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
/// TODO : keep multi-values uniques !
|
/// TODO : keep multi-values uniques !
|
||||||
/// it should be done in record_adapter
|
/// it should be done in record_adapter
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param databox_field[] $struct
|
* @param databox_field[] $struct
|
||||||
* @param record_adapter $record
|
* @param record_adapter $record
|
||||||
@@ -94,12 +105,10 @@ class V3MetadatasController extends Controller
|
|||||||
private function do_metadatas($struct, record_adapter $record, $metadatas)
|
private function do_metadatas($struct, record_adapter $record, $metadatas)
|
||||||
{
|
{
|
||||||
$structByKey = [];
|
$structByKey = [];
|
||||||
$nameToStrucId = [];
|
|
||||||
$allStructFields = [];
|
$allStructFields = [];
|
||||||
foreach ($struct as $f) {
|
foreach ($struct as $f) {
|
||||||
$nameToStrucId[$f->get_name()] = $f->get_id();
|
|
||||||
$allStructFields[$f->get_id()] = $f;
|
$allStructFields[$f->get_id()] = $f;
|
||||||
$structByKey[$f->get_id()] = &$allStructFields[$f->get_id()];;
|
$structByKey[$f->get_id()] = &$allStructFields[$f->get_id()];
|
||||||
$structByKey[$f->get_name()] = &$allStructFields[$f->get_id()];
|
$structByKey[$f->get_name()] = &$allStructFields[$f->get_id()];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +132,9 @@ class V3MetadatasController extends Controller
|
|||||||
$fields_list[] = $structByKey[$k]->get_name();
|
$fields_list[] = $structByKey[$k]->get_name();
|
||||||
$struct_fields[$structByKey[$k]->get_id()] = $structByKey[$k];
|
$struct_fields[$structByKey[$k]->get_id()] = $structByKey[$k];
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
throw new Exception(sprintf("unknown field (%s).", $k));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -187,13 +199,12 @@ class V3MetadatasController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $struct
|
|
||||||
* @param $record
|
* @param $record
|
||||||
* @param $statuses
|
* @param $statuses
|
||||||
* @return array
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function do_status($struct, $record, $statuses)
|
private function do_status(record_adapter $record, $statuses)
|
||||||
{
|
{
|
||||||
$datas = strrev($record->getStatus());
|
$datas = strrev($record->getStatus());
|
||||||
|
|
@@ -115,13 +115,13 @@ class MoveCollectionController extends Controller
|
|||||||
|
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
$oldCollectionId = $record->getCollection()->get_coll_id();
|
$oldCollectionId = $record->getCollection()->get_coll_id();
|
||||||
$record->move_to_collection($collection, $this->getApplicationBox());
|
$record->move_to_collection($collection);
|
||||||
|
|
||||||
if ($request->request->get("chg_coll_son") == "1") {
|
if ($request->request->get("chg_coll_son") == "1") {
|
||||||
/** @var \record_adapter $child */
|
/** @var \record_adapter $child */
|
||||||
foreach ($record->getChildren() as $child) {
|
foreach ($record->getChildren() as $child) {
|
||||||
if ($this->getAclForUser()->has_right_on_base($child->getBaseId(), \ACL::CANDELETERECORD)) {
|
if ($this->getAclForUser()->has_right_on_base($child->getBaseId(), \ACL::CANDELETERECORD)) {
|
||||||
$child->move_to_collection($collection, $this->getApplicationBox());
|
$child->move_to_collection($collection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -242,7 +242,7 @@ class RecordController extends Controller
|
|||||||
$this->getEventDispatcher()->dispatch(RecordEvents::DELETE, new DeleteEvent($record));
|
$this->getEventDispatcher()->dispatch(RecordEvents::DELETE, new DeleteEvent($record));
|
||||||
} else {
|
} else {
|
||||||
// move to trash collection
|
// move to trash collection
|
||||||
$record->move_to_collection($trashCollectionsBySbasId[$sbasId], $this->getApplicationBox());
|
$record->move_to_collection($trashCollectionsBySbasId[$sbasId]);
|
||||||
// disable permalinks
|
// disable permalinks
|
||||||
foreach($record->get_subdefs() as $subdef) {
|
foreach($record->get_subdefs() as $subdef) {
|
||||||
if( ($pl = $subdef->get_permalink()) ) {
|
if( ($pl = $subdef->get_permalink()) ) {
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
namespace Alchemy\Phrasea\ControllerProvider\Api;
|
namespace Alchemy\Phrasea\ControllerProvider\Api;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Alchemy\Phrasea\Controller\Api\V3\V3MetadatasController;
|
use Alchemy\Phrasea\Controller\Api\V3\V3RecordController;
|
||||||
use Alchemy\Phrasea\Controller\Api\V3\V3ResultHelpers;
|
use Alchemy\Phrasea\Controller\Api\V3\V3ResultHelpers;
|
||||||
use Alchemy\Phrasea\Controller\Api\V3\V3SearchController;
|
use Alchemy\Phrasea\Controller\Api\V3\V3SearchController;
|
||||||
use Alchemy\Phrasea\Controller\Api\V3\V3StoriesController;
|
use Alchemy\Phrasea\Controller\Api\V3\V3StoriesController;
|
||||||
@@ -28,7 +28,7 @@ class V3 extends Api implements ControllerProviderInterface, ServiceProviderInte
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
$app['controller.api.v3.metadatas'] = $app->share(function (PhraseaApplication $app) {
|
$app['controller.api.v3.metadatas'] = $app->share(function (PhraseaApplication $app) {
|
||||||
return (new V3MetadatasController($app))
|
return (new V3RecordController($app))
|
||||||
->setJsonBodyHelper($app['json.body_helper'])
|
->setJsonBodyHelper($app['json.body_helper'])
|
||||||
->setDispatcher($app['dispatcher'])
|
->setDispatcher($app['dispatcher'])
|
||||||
;
|
;
|
||||||
@@ -70,9 +70,9 @@ class V3 extends Api implements ControllerProviderInterface, ServiceProviderInte
|
|||||||
$controllers->match('/search/', 'controller.api.v3.search:searchAction');
|
$controllers->match('/search/', 'controller.api.v3.search:searchAction');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @uses V3MetadatasController::setmetadatasAction()
|
* @uses V3RecordController::indexAction_patch()
|
||||||
*/
|
*/
|
||||||
$controllers->patch('/records/{databox_id}/{record_id}/setmetadatas/', 'controller.api.v3.metadatas:setmetadatasAction')
|
$controllers->patch('/records/{databox_id}/{record_id}/', 'controller.api.v3.metadatas:indexAction_patch')
|
||||||
->before('controller.api.v1:ensureCanAccessToRecord')
|
->before('controller.api.v1:ensureCanAccessToRecord')
|
||||||
->before('controller.api.v1:ensureCanModifyRecord')
|
->before('controller.api.v1:ensureCanModifyRecord')
|
||||||
->assert('databox_id', '\d+')
|
->assert('databox_id', '\d+')
|
||||||
|
@@ -74,7 +74,6 @@ class RecordMoverJob extends AbstractJob
|
|||||||
|
|
||||||
private function processData(Application $app, $row, $logsql)
|
private function processData(Application $app, $row, $logsql)
|
||||||
{
|
{
|
||||||
/** @var databox $databox */
|
|
||||||
$databox = $app->findDataboxById($row['sbas_id']);
|
$databox = $app->findDataboxById($row['sbas_id']);
|
||||||
$rec = $databox->get_record($row['record_id']);
|
$rec = $databox->get_record($row['record_id']);
|
||||||
|
|
||||||
@@ -83,7 +82,7 @@ class RecordMoverJob extends AbstractJob
|
|||||||
// change collection ?
|
// change collection ?
|
||||||
if (array_key_exists('coll', $row)) {
|
if (array_key_exists('coll', $row)) {
|
||||||
$coll = \collection::getByCollectionId($app, $databox, $row['coll']);
|
$coll = \collection::getByCollectionId($app, $databox, $row['coll']);
|
||||||
$rec->move_to_collection($coll, $app['phraseanet.appbox']);
|
$rec->move_to_collection($coll);
|
||||||
if ($logsql) {
|
if ($logsql) {
|
||||||
$this->log('debug', sprintf("on sbas %s move rid %s to coll %s \n", $row['sbas_id'], $row['record_id'], $coll->get_coll_id()));
|
$this->log('debug', sprintf("on sbas %s move rid %s to coll %s \n", $row['sbas_id'], $row['record_id'], $coll->get_coll_id()));
|
||||||
}
|
}
|
||||||
|
@@ -522,10 +522,11 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param collection $collection
|
* @param collection $collection
|
||||||
* @param appbox $appbox
|
* @param appbox $appbox WTF this parm is useless
|
||||||
* @return record_adapter
|
* @return record_adapter
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function move_to_collection(collection $collection, appbox $appbox)
|
public function move_to_collection(collection $collection, appbox $appbox = null)
|
||||||
{
|
{
|
||||||
if ($this->getCollection()->get_base_id() === $collection->get_base_id()) {
|
if ($this->getCollection()->get_base_id() === $collection->get_base_id()) {
|
||||||
return $this;
|
return $this;
|
||||||
|
@@ -118,7 +118,7 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
public function testDatafilesRouteNotAuthenticatedIsOkInPublicFeed()
|
public function testDatafilesRouteNotAuthenticatedIsOkInPublicFeed()
|
||||||
{
|
{
|
||||||
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
|
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
|
||||||
self::$DI['record_5']->move_to_collection(self::$DI['collection_no_access'], self::$DI['app']['phraseanet.appbox']);
|
self::$DI['record_5']->move_to_collection(self::$DI['collection_no_access']);
|
||||||
$path = self::$DI['app']['url_generator']->generate('datafile', [
|
$path = self::$DI['app']['url_generator']->generate('datafile', [
|
||||||
'sbas_id' => self::$DI['record_5']->get_sbas_id(),
|
'sbas_id' => self::$DI['record_5']->get_sbas_id(),
|
||||||
'record_id' => self::$DI['record_5']->get_record_id(),
|
'record_id' => self::$DI['record_5']->get_record_id(),
|
||||||
@@ -127,7 +127,7 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
self::$DI['client']->request('GET', $path);
|
self::$DI['client']->request('GET', $path);
|
||||||
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
|
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
|
||||||
self::$DI['record_5']->move_to_collection(self::$DI['collection'], self::$DI['app']['phraseanet.appbox']);
|
self::$DI['record_5']->move_to_collection(self::$DI['collection']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDatafilesRouteNotAuthenticatedUnknownSubdef()
|
public function testDatafilesRouteNotAuthenticatedUnknownSubdef()
|
||||||
|
Reference in New Issue
Block a user