mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 03:53:13 +00:00
Refactor API tests, add tests for feeds
This commit is contained in:
@@ -413,7 +413,6 @@ return call_user_func(function() {
|
||||
}
|
||||
);
|
||||
|
||||
$app->match('/records/add/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* Route : /records/search/
|
||||
@@ -742,6 +741,26 @@ return call_user_func(function() {
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
$route = '/feeds/content/';
|
||||
$app->get(
|
||||
$route, function() use ($app) {
|
||||
$result = $app['api']->get_publications($app['request'], $app['Core']->getAuthenticatedUser());
|
||||
|
||||
return $result->get_response();
|
||||
}
|
||||
);
|
||||
|
||||
$route = '/feeds/entry/{entry_id}/';
|
||||
$app->get(
|
||||
$route, function($entry_id) use ($app) {
|
||||
$result = $app['api']->get_feed_entry($app['request'], $entry_id, $app['Core']->getAuthenticatedUser());
|
||||
|
||||
return $result->get_response();
|
||||
}
|
||||
)->assert('entry_id', '\d+');
|
||||
$app->get('/feeds/entry/{entry_id}/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* Route : /feeds/PUBLICATION_ID/content/
|
||||
*
|
||||
|
@@ -269,6 +269,9 @@ interface API_V1_Interface
|
||||
*/
|
||||
public function get_publication(Request $request, $publication_id, User_Adapter &$user);
|
||||
|
||||
public function get_publications(Request $request, User_Adapter &$user);
|
||||
|
||||
public function get_feed_entry(Request $request, $entry, User_Adapter &$user);
|
||||
/**
|
||||
* Route : /users/search/FORMAT/
|
||||
*
|
||||
@@ -290,6 +293,8 @@ interface API_V1_Interface
|
||||
*/
|
||||
public function get_user_acces(Request $request, $usr_id);
|
||||
|
||||
public function add_record(Application $app, Request $request);
|
||||
|
||||
/**
|
||||
* Route : /users/add/FORMAT/
|
||||
*
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Border\Manager as BorderManager;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Silex\Application;
|
||||
|
||||
@@ -109,25 +110,31 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
|
||||
$ret = array();
|
||||
foreach ($tasks as $task) {
|
||||
$ret[$task->getID()] = array(
|
||||
$ret[] = $this->list_task($task);
|
||||
}
|
||||
|
||||
$result->set_datas(array('tasks' => $ret));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function list_task(\task_abstract $task)
|
||||
{
|
||||
return array(
|
||||
'id' => $task->getID(),
|
||||
'name' => $task->getName(),
|
||||
'state' => $task->getState(),
|
||||
'pid' => $task->getPID(),
|
||||
'title' => $task->getTitle(),
|
||||
'last_exec_time' => $task->getLastExecTime()
|
||||
'last_exec_time' => $task->getLastExecTime() ? $task->getLastExecTime()->format(DATE_ATOM) : null
|
||||
);
|
||||
}
|
||||
|
||||
$result->set_datas($ret);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get informations about an identified task
|
||||
*
|
||||
* @param \Silex\Application $app The API silex application
|
||||
* @param type $task_id
|
||||
* @param integer $task_id
|
||||
* @return \API_V1_result
|
||||
*/
|
||||
public function get_task(Application $app, $taskId)
|
||||
@@ -136,24 +143,11 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
|
||||
$appbox = \appbox::get_instance($app['Core']);
|
||||
$taskManager = new task_manager($appbox);
|
||||
$ret = array();
|
||||
try {
|
||||
$task = $taskManager->getTask($taskId);
|
||||
$ret['id'] = $task->getID();
|
||||
$ret['state'] = $task->getState();
|
||||
$ret['pid'] = $task->getPID();
|
||||
$ret['title'] = $task->getTitle();
|
||||
$ret['last_exec_time'] = $task->getLastExecTime();
|
||||
} catch (\Exception_NotFound $e) {
|
||||
$result->set_error_code(404);
|
||||
$ret = array('success' => false);
|
||||
} catch (\Exception_InvalidArgument $e) {
|
||||
$result->set_error_code(400);
|
||||
$ret = array('success' => false);
|
||||
} catch (\Exception $e) {
|
||||
$result->set_error_code(500);
|
||||
$ret = array('success' => false);
|
||||
}
|
||||
|
||||
$ret = array(
|
||||
'task' => $this->list_task($taskManager->getTask($taskId))
|
||||
);
|
||||
|
||||
$result->set_datas($ret);
|
||||
|
||||
return $result;
|
||||
@@ -163,7 +157,7 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
* Start a specified task
|
||||
*
|
||||
* @param \Silex\Application $app The API silex application
|
||||
* @param type $task_id The task id
|
||||
* @param integer $task_id The task id
|
||||
* @return \API_V1_result
|
||||
*/
|
||||
public function start_task(Application $app, $taskId)
|
||||
@@ -172,21 +166,13 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
|
||||
$appbox = \appbox::get_instance($app['Core']);
|
||||
$taskManager = new \task_manager($appbox);
|
||||
$ret = array('success' => true);
|
||||
try {
|
||||
|
||||
$task = $taskManager->getTask($taskId);
|
||||
if ( ! in_array($task->getState(), array(\task_abstract::STATE_TOSTART, \task_abstract::STATE_STARTED))) {
|
||||
$task->setState(\task_abstract::STATE_TOSTART);
|
||||
} catch (\Exception_NotFound $e) {
|
||||
$result->set_error_code(404);
|
||||
$ret = array('success' => false);
|
||||
} catch (\Exception_InvalidArgument $e) {
|
||||
$result->set_error_code(400);
|
||||
$ret = array('success' => false);
|
||||
} catch (\Exception $e) {
|
||||
$result->set_error_code(500);
|
||||
$ret = array('success' => false);
|
||||
}
|
||||
$result->set_datas($ret);
|
||||
|
||||
$result->set_datas(array('task' => $this->list_task($task)));
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -195,7 +181,7 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
* Stop a specified task
|
||||
*
|
||||
* @param \Silex\Application $app The API silex application
|
||||
* @param type $task_id The task id
|
||||
* @param integer $task_id The task id
|
||||
* @return \API_V1_result
|
||||
*/
|
||||
public function stop_task(Application $app, $taskId)
|
||||
@@ -204,21 +190,12 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
|
||||
$appbox = \appbox::get_instance($app['Core']);
|
||||
$taskManager = new \task_manager($appbox);
|
||||
$ret = array();
|
||||
try {
|
||||
|
||||
$task = $taskManager->getTask($taskId);
|
||||
if ( ! in_array($task->getState(), array(\task_abstract::STATE_TOSTOP, \task_abstract::STATE_STOPPED))) {
|
||||
$task->setState(\task_abstract::STATE_TOSTOP);
|
||||
} catch (\Exception_NotFound $e) {
|
||||
$result->set_error_code(404);
|
||||
$ret = array('success' => false);
|
||||
} catch (\Exception_InvalidArgument $e) {
|
||||
$result->set_error_code(400);
|
||||
$ret = array('success' => false);
|
||||
} catch (\Exception $e) {
|
||||
$result->set_error_code(500);
|
||||
$ret = array('success' => false);
|
||||
}
|
||||
$result->set_datas($ret);
|
||||
$result->set_datas(array('task' => $this->list_task($task)));
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -229,22 +206,19 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
* - autostart
|
||||
*
|
||||
* @param \Silex\Application $app Silex application
|
||||
* @param type $task_id the task id
|
||||
* @param integer $task_id the task id
|
||||
* @return \API_V1_result
|
||||
* @throws \Exception_InvalidArgument
|
||||
* @throws \API_V1_exception_badrequest
|
||||
*/
|
||||
public function set_task_property(Application $app, $taskId)
|
||||
{
|
||||
$result = new API_V1_result($app['request'], $this);
|
||||
|
||||
$name = $app['request']->get('name');
|
||||
$title = $app['request']->get('title');
|
||||
$autostart = $app['request']->get('autostart');
|
||||
|
||||
$ret = array('success' => false);
|
||||
|
||||
try {
|
||||
if (null === $name && null === $autostart) {
|
||||
throw new \Exception_InvalidArgument();
|
||||
if (null === $title && null === $autostart) {
|
||||
throw new \API_V1_exception_badrequest();
|
||||
}
|
||||
|
||||
$appbox = \appbox::get_instance($app['Core']);
|
||||
@@ -253,26 +227,15 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
|
||||
$task = $taskManager->getTask($taskId);
|
||||
|
||||
if ($name) {
|
||||
$task->setTitle($name);
|
||||
if ($title) {
|
||||
$task->setTitle($title);
|
||||
}
|
||||
|
||||
if ($autostart) {
|
||||
$task->setActive( ! ! $autostart);
|
||||
}
|
||||
|
||||
$ret = array('success' => true);
|
||||
} catch (\Exception_NotFound $e) {
|
||||
$result->set_error_code(404);
|
||||
$ret = array('success' => false);
|
||||
} catch (\Exception_InvalidArgument $e) {
|
||||
$result->set_error_code(400);
|
||||
$ret = array('success' => false);
|
||||
} catch (\Exception $e) {
|
||||
$result->set_error_code(500);
|
||||
$ret = array('success' => false);
|
||||
}
|
||||
$result->set_datas($ret);
|
||||
$result->set_datas(array('task' => $this->list_task($task)));
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -711,10 +674,10 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
|
||||
switch ($request->get('forceBehavior')) {
|
||||
case '0' :
|
||||
$behavior = \Alchemy\Phrasea\Border\Manager::FORCE_RECORD;
|
||||
$behavior = BorderManager::FORCE_RECORD;
|
||||
break;
|
||||
case '1' :
|
||||
$behavior = \Alchemy\Phrasea\Border\Manager::FORCE_LAZARET;
|
||||
$behavior = BorderManager::FORCE_LAZARET;
|
||||
break;
|
||||
case null:
|
||||
$behavior = null;
|
||||
@@ -736,7 +699,7 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
}
|
||||
if ($output instanceof \Entities\LazaretFile) {
|
||||
$ret['entity'] = '1';
|
||||
$ret['reasons'] = $reasons;
|
||||
$ret['reasons'] = $behavior === BorderManager::FORCE_LAZARET ? array() : $reasons;
|
||||
$ret['lazaretFile'] = $this->list_lazaret_file($output);
|
||||
}
|
||||
|
||||
@@ -776,7 +739,7 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
'sha256' => $file->getSha256(),
|
||||
'uuid' => $file->getUuid(),
|
||||
'forced' => $file->getForced(),
|
||||
'checks' => $checks,
|
||||
'checks' => $file->getForced() ? array() : $checks,
|
||||
'created_on' => $file->getCreated()->format(DATE_ATOM),
|
||||
'updated_on' => $file->getUpdated()->format(DATE_ATOM),
|
||||
);
|
||||
@@ -1495,13 +1458,15 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function get_feed_entry(Request $request, $entry, User_Adapter &$user)
|
||||
public function get_feed_entry(Request $request, $entry_id, User_Adapter &$user)
|
||||
{
|
||||
$result = new API_V1_result($request, $this);
|
||||
|
||||
$entry = Feed_Entry_Adapter::load_from_id($this->appbox, $id);
|
||||
$entry = Feed_Entry_Adapter::load_from_id($this->appbox, $entry_id);
|
||||
|
||||
if ( ! $user->ACL()->has_access_to_base($entry->get_feed()->get_collection()->get_base_id())) {
|
||||
$collection = $entry->get_feed()->get_collection();
|
||||
|
||||
if (null !== $collection && ! $user->ACL()->has_access_to_base($collection->get_base_id())) {
|
||||
throw new \API_V1_exception_forbidden('You have not access to the parent feed');
|
||||
}
|
||||
|
||||
@@ -1561,10 +1526,7 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
$out[$entry->get_id()] = $this->list_publication_entry($entry);
|
||||
}
|
||||
|
||||
return array(
|
||||
'offset_start' => $offset_start
|
||||
, 'entries' => $out
|
||||
);
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1581,6 +1543,7 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $entry->get_id(),
|
||||
'author_email' => $entry->get_author_email(),
|
||||
'author_name' => $entry->get_author_name(),
|
||||
'created_on' => $entry->get_created_on()->format(DATE_ATOM),
|
||||
@@ -1588,6 +1551,7 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
'title' => $entry->get_title(),
|
||||
'subtitle' => $entry->get_subtitle(),
|
||||
'items' => $items,
|
||||
'feed_url' => '/feeds/' . $entry->get_feed()->get_id() . '/content/',
|
||||
'url' => '/feeds/entry/' . $entry->get_id() . '/',
|
||||
);
|
||||
}
|
||||
@@ -1644,6 +1608,10 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
*/
|
||||
protected function list_embedable_media(media_subdef &$media, registryInterface &$registry)
|
||||
{
|
||||
if ( ! $media->is_physically_present()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($media->get_permalink() instanceof media_Permalink_Adapter) {
|
||||
$permalink = $this->list_permalink($media->get_permalink(), $registry);
|
||||
} else {
|
||||
|
@@ -534,7 +534,7 @@ class caption_Field_Value implements cache_cacheableInterface
|
||||
*/
|
||||
public function get_cache_key($option = null)
|
||||
{
|
||||
return 'caption_fieldvalue_' . $this->record->get_serialize_key() . ($option ? '_' . $option : '');
|
||||
return 'caption_fieldvalue_' . $this->id . '_' . $this->record->get_serialize_key() . ($option ? '_' . $option : '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -749,6 +749,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
|
||||
foreach ($rs as $row) {
|
||||
switch (true) {
|
||||
case preg_match('/[0-9]?\.[0-9]+/', $row['value']):
|
||||
$this->technical_datas[$row['name']] = (float) $row['value'];
|
||||
break;
|
||||
case ctype_digit($row['value']):
|
||||
$this->technical_datas[$row['name']] = (int) $row['value'];
|
||||
break;
|
||||
@@ -779,7 +782,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
*/
|
||||
public function get_caption()
|
||||
{
|
||||
|
||||
return new caption_record($this, $this->get_databox());
|
||||
}
|
||||
|
||||
@@ -1337,7 +1339,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
$record->delete_data_from_cache(record_adapter::CACHE_SUBDEFS);
|
||||
|
||||
$record->insertTechnicalDatas();
|
||||
$record->rebuild_subdefs();
|
||||
|
||||
return $record;
|
||||
}
|
||||
@@ -1363,6 +1364,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
foreach ($document->readTechnicalDatas() as $name => $value) {
|
||||
if (is_null($value)) {
|
||||
continue;
|
||||
} elseif (is_bool($value)) {
|
||||
if ($value) {
|
||||
$value = 1;
|
||||
} else {
|
||||
$value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$stmt->execute(array(
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user