fix: [feed] fix REST problems

pull/5253/head
Pierre-Jean Grenier 2019-10-02 16:41:03 +02:00
parent 027aa91dd4
commit 8415cea5db
2 changed files with 13 additions and 4 deletions

View File

@ -132,7 +132,10 @@ class FeedsController extends AppController
public function importFeeds()
{
if ($this->request->is('post')) {
$results = $this->Feed->importFeeds($this->request->data['Feed']['json'], $this->Auth->user());
if (isset($this->request->data['Feed']['json'])) {
$this->request->data = $this->request->data['Feed']['json'];
}
$results = $this->Feed->importFeeds($this->request->data, $this->Auth->user());
if ($results['successes'] > 0) {
$flashType = 'success';
$message = $results['successes'] . ' new feeds added.';
@ -505,8 +508,12 @@ class FeedsController extends AppController
}
}
}
$this->Flash->success($message);
$this->redirect(array('action' => 'index'));
if ($this->_isRest()) {
return $this->RestResponse->viewData(array('result' => $message), $this->response->type());
} else {
$this->Flash->success($message);
$this->redirect(array('action' => 'index'));
}
}
public function getEvent($feedId, $eventUuid, $all = false)

View File

@ -1231,7 +1231,9 @@ class Feed extends AppModel
public function importFeeds($feeds, $user, $default = false)
{
$feeds = json_decode($feeds, true);
if (is_string($feeds)) {
$feeds = json_decode($feeds, true);
}
if ($feeds && !isset($feeds[0])) {
$feeds = array($feeds);
}