1 <?php
 2 /**
 3  * @package redaxo\structure
 4  */
 5 class rex_api_article_move extends rex_api_function
 6 {
 7     /**
 8      * @return rex_api_result
 9      *
10      * @throws rex_api_exception
11      */
12     public function execute()
13     {
14         // The article to move
15         $article_id = rex_request('article_id', 'int');
16         $category_id = rex_article::get($article_id)->getCategoryId();
17         // The destination category in which the given category will be moved
18         $category_id_new = rex_request('category_id_new', 'int');
19 
20         $user = rex::getUser();
21 
22         // Check permissions
23         if ($user->hasPerm('moveArticle[]') &&
24             $user->getComplexPerm('structure')->hasCategoryPerm($category_id_new)
25         ) {
26             if (rex_article_service::moveArticle($article_id, $category_id, $category_id_new)) {
27                 $result = new rex_api_result(true, rex_i18n::msg('content_articlemoved'));
28             } else {
29                 $result = new rex_api_result(false, rex_i18n::msg('content_errormovearticle'));
30             }
31 
32             return $result;
33         }
34 
35         throw new rex_api_exception(rex_i18n::msg('no_rights_to_this_function'));
36     }
37 
38     protected function requiresCsrfProtection()
39     {
40         return true;
41     }
42 }
43