<commit_before><?php

class ContentController extends ApiController
{
    public function accessRules()
    {
        return array(
            array('allow',
                'actions' => array('index', 'tag')
            ),
            array('allow',
                'actions' => array('indexPost', 'indexDelete', 'tagPost', 'tagDelete'),
                'expression' => '$user!=NULL'
            ),
            array('allow',
                'actions' => array('uploadPost'),
            ),
            array('allow',
                'actions' => array('publish', 'unpublish'),
                'expression' => '$user->role->hasPermission("publish")'
            ),
            array('deny')
        );
    }

    /**
     * [GET] [/content]
     * Retrieves an article by the requested id, or retrieves all articles based upon permissions
     *
     * NOTE: This endpoint behaves differently for authenticated and unauthenticated users. Authenticated users are show posts they can mutate, whereas
     *
     * @param int $id   The Content id
     */
    public function actionIndex($id=NULL)
    {
        $model = new Content('search');
        $model->unsetAttributes();  // clear any default values
	    $model->pageSize = 20;
        
        if(isset($_GET['Content']))
            $model->attributes = $_GET['Content'];

        // Published is now a special field in the API, so we need to do type conversions on it to make things easier in the search() method
        if ($model->published == 'true')
            $model->published = true;
        else if ($model->published == 'false')
            $model->published = false;

        // Let the search getter do all tha hard work
        if ($id != NULL)
            $model->id = $id;

        // Normaly users can only see published entries
        $role = Cii::get($this->user, 'role', NULL);
        $hiddenFields = array('category_id', 'parent_id', 'author_id');

        if ($this->user == NULL || UserRoles::model()->isA('user', $this->user->role->id))
        {
            $model->status = 1;
            $model->published = true;
            $model->password = "";

            array_push($hiddenFields, 'password', '<PASSWORD>');
        }
        else if ($this->user->role->isA('admin'))
        {
            // Users with this role can do everything
        }
        else if ($this->user->role->isA('publisher') || $this->user->role->isA('author'))
        {
            // Restrict collaborates to only being able to see their own content 
            $model->author_id = $this->user->id;
        }

        // Modify the pagination variable to use page instead of Content page
        $dataProvider = $model->search();
        $dataProvider->pagination = array(
            'pageVar' => 'page'
        );

        // Throw a 404 if we exceed the number of available results
        if ($dataProvider->totalItemCount == 0 || ($dataProvider->totalItemCount / ($dataProvider->itemCount * Cii::get($_GET, 'page', 1))) < 1)
            throw new CHttpException(404, Yii::t('Api.content', 'No results found'));

        $response = array();

        foreach ($dataProvider->getData() as $content)
        {
            $response[] = $content->getAPIAttributes($hiddenFields, array(
                            'author' => array(
                                'password',
                                'activation_key',
                                'email',
                                'about',
                                'user_role',
                                'status',
                                'created',
                                'updated'
                            ), 
                            'category' => array(
                                'parent_id'
                            ),
                            'metadata' => array(
                                'content_id'
                            )
                        ));
        }

        return $response;
    }

    /**
     * [POST] [/content/<id>] [/content]
     * Creates or modifies an existing entry
     * @param int $id   The Content id
     */
    public function actionIndexPost($id=NULL)
    {
        if ($id===NULL)
            return $this->createNewPost();
        else
            return $this->updatePost($id);
    }

    /**
     * [DELETE] [/content/<id>]
     * Deletes an article
     * @param int $id   The Content id
     */
    public function actionIndexDelete($id=NULL)
    {
        if (!$this->user->role->hasPermission('delete'))
            throw new CHttpException(403, Yii::t('Api.content', 'You do not have permission to delete entries.'));

        return $this->loadModel($id)->delete();
    }

    /**
     * [GET] [/content/tag/<id>]
     * Retrieves tags for a given entry
     */
    public function actionTag($id=NULL)
    {
        $model = $this->loadModel($id);
        return $model->getTags();
    }

    /**
     * [POST} [/content/tag/<id>]
     * Creates a new tag for a given entry
     */
    public function actionTagPost($id=NULL)
    {
        $model = $this->loadModel($id);

        if (!($this->user->id == $model->author->id || $this->user->role->hasPermission('modify')))
            throw new CHttpException(403, Yii::t('Api.content', 'You do not have permission to modify tags.'));

        if ($model->addTag(Cii::get($_POST, 'tag')))
            return $model->getTags();

        return $this->returnError(400, NULL, $model->getErrors());

    }<commit_msg>Delete method update<commit_after><?php

class ContentController extends ApiController
{
    public function accessRules()
    {
        return array(
            array('allow',
                'actions' => array('index', 'tag')
            ),
            array('allow',
                'actions' => array('indexPost', 'indexDelete', 'tagPost', 'tagDelete'),
                'expression' => '$user!=NULL'
            ),
            array('allow',
                'actions' => array('uploadPost'),
            ),
            array('allow',
                'actions' => array('publish', 'unpublish'),
                'expression' => '$user->role->hasPermission("publish")'
            ),
            array('deny')
        );
    }

    /**
     * [GET] [/content]
     * Retrieves an article by the requested id, or retrieves all articles based upon permissions
     *
     * NOTE: This endpoint behaves differently for authenticated and unauthenticated users. Authenticated users are show posts they can mutate, whereas
     *
     * @param int $id   The Content id
     */
    public function actionIndex($id=NULL)
    {
        $model = new Content('search');
        $model->unsetAttributes();  // clear any default values
	    $model->pageSize = 20;
        
        if(isset($_GET['Content']))
            $model->attributes = $_GET['Content'];

        // Published is now a special field in the API, so we need to do type conversions on it to make things easier in the search() method
        if ($model->published == 'true')
            $model->published = true;
        else if ($model->published == 'false')
            $model->published = false;

        // Let the search getter do all tha hard work
        if ($id != NULL)
            $model->id = $id;

        // Normaly users can only see published entries
        $role = Cii::get($this->user, 'role', NULL);
        $hiddenFields = array('category_id', 'parent_id', 'author_id');

        if ($this->user == NULL || UserRoles::model()->isA('user', $this->user->role->id))
        {
            $model->status = 1;
            $model->published = true;
            $model->password = "";

            array_push($hiddenFields, 'password', '<PASSWORD>');
        }
        else if ($this->user->role->isA('admin'))
        {
            // Users with this role can do everything
        }
        else if ($this->user->role->isA('publisher') || $this->user->role->isA('author'))
        {
            // Restrict collaborates to only being able to see their own content 
            $model->author_id = $this->user->id;
        }

        // Modify the pagination variable to use page instead of Content page
        $dataProvider = $model->search();
        $dataProvider->pagination = array(
            'pageVar' => 'page'
        );

        // Throw a 404 if we exceed the number of available results
        if ($dataProvider->totalItemCount == 0 || ($dataProvider->totalItemCount / ($dataProvider->itemCount * Cii::get($_GET, 'page', 1))) < 1)
            throw new CHttpException(404, Yii::t('Api.content', 'No results found'));

        $response = array();

        foreach ($dataProvider->getData() as $content)
        {
            $response[] = $content->getAPIAttributes($hiddenFields, array(
                            'author' => array(
                                'password',
                                'activation_key',
                                'email',
                                'about',
                                'user_role',
                                'status',
                                'created',
                                'updated'
                            ), 
                            'category' => array(
                                'parent_id'
                            ),
                            'metadata' => array(
                                'content_id'
                            )
                        ));
        }

        return $response;
    }

    /**
     * [POST] [/content/<id>] [/content]
     * Creates or modifies an existing entry
     * @param int $id   The Content id
     */
    public function actionIndexPost($id=NULL)
    {
        if ($id===NULL)
            return $this->createNewPost();
        else
            return $this->updatePost($id);
    }

    /**
     * [DELETE] [/content/<id>]
     * Deletes an article
     * @param int $id   The Content id
     */
    public function actionIndexDelete($id=NULL)
    {
        if (!$this->user->role->hasPermission('delete'))
            throw new CHttpException(403, Yii::t('Api.content', 'You do not have permission to delete entries.'));

        return $this->loadModel($id)->deleteAllByAttributes(array('id' => $id));
    }

    /**
     * [GET] [/content/tag/<id>]
     * Retrieves tags for a given entry
     */
    public function actionTag($id=NULL)
    {
        $model = $this->loadModel($id);
        return $model->getTags();
    }

    /**
     * [POST} [/content/tag/<id>]
     * Creates a new tag for a given entry
     */
    public function actionTagPost($id=NULL)
    {
        $model = $this->loadModel($id);

        if (!($this->user->id == $model->author->id || $this->user->role->hasPermission('modify')))
            throw new CHttpException(403, Yii::t('Api.content', 'You do not have permission to modify tags.'));

        if ($model->addTag(Cii::get($_POST, 'tag')))
            return $model->getTags();

        return $this->returnError(400, NULL, $model->getErrors());

    }
{'fraction_non_alphanumeric': 0.14113924050632912, 'fraction_numerical': 0.0037974683544303796, 'mean_word_length': 1.611806375442739, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 152, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4491685', 'n_tokens_mistral': 2976, 'n_tokens_neox': 2856, 'n_words': 755}