new: [API] Taxonomy export

pull/7558/head
Jakub Onderka 2021-07-08 12:18:14 +02:00
parent bcbc34b3b8
commit eafc213324
2 changed files with 50 additions and 0 deletions

View File

@ -651,6 +651,7 @@ class ACLComponent extends Component
'toggleRequired' => array('perm_site_admin'),
'update' => array(),
'import' => [],
'export' => ['*'],
'view' => array('*'),
'unhideTag' => array('perm_tagger'),
'hideTag' => array('perm_tagger'),

View File

@ -113,6 +113,55 @@ class TaxonomiesController extends AppController
$this->set('title_for_layout', __('%s Taxonomy Library', h(strtoupper($taxonomy['Taxonomy']['namespace']))));
}
public function export($id)
{
$taxonomy = $this->Taxonomy->find('first', [
'recursive' => -1,
'contain' => ['TaxonomyPredicate' => ['TaxonomyEntry']],
'conditions' => is_numeric($id) ? ['Taxonomy.id' => $id] : ['LOWER(Taxonomy.namespace)' => mb_strtolower($id)],
]);
if (empty($taxonomy)) {
throw new NotFoundException(__('Taxonomy not found.'));
}
$data = [
'namespace' => $taxonomy['Taxonomy']['namespace'],
'description' => $taxonomy['Taxonomy']['description'],
'version' => (int)$taxonomy['Taxonomy']['version'],
'exclusive' => $taxonomy['Taxonomy']['exclusive'],
'predicates' => [],
];
foreach ($taxonomy['TaxonomyPredicate'] as $predicate) {
$predicateOutput = [];
foreach (['value', 'expanded', 'colour', 'description', 'exclusive', 'numerical_value'] as $field) {
if (isset($predicate[$field]) && !empty($predicate[$field])) {
$predicateOutput[$field] = $predicate[$field];
}
}
$data['predicates'][] = $predicateOutput;
if (!empty($predicate['TaxonomyEntry'])) {
$entries = [];
foreach ($predicate['TaxonomyEntry'] as $entry) {
$entryOutput = [];
foreach(['value', 'expanded', 'colour', 'description', 'exclusive', 'numerical_value'] as $field) {
if (isset($entry[$field]) && !empty($entry[$field])) {
$entryOutput[$field] = $entry[$field];
}
}
$entries[] = $entryOutput;
}
$data['values'][] = [
'predicate' => $predicate['value'],
'entry' => $entries,
];
}
}
return $this->RestResponse->viewData($data, 'json');
}
public function enable($id)
{
if (!$this->_isSiteAdmin() || !$this->request->is('Post')) {