<commit_before><?php

class Controller_Backend_Post extends \Controller_Base_Backend
{

    public function action_index()
    {
    	$this->dataGlobal['pageTitle'] = __('backend.post.manage');
    	$this->data['posts'] = \Model_Post::find('all');
		$this->theme->set_partial('content', 'backend/post/index')->set($this->data); 
    }

    public function action_add($id = null)
    {
        $this->data['isUpdate'] = $isUpdate = ($id !== null) ? true : false;

        // Prepare form fieldset
        $form = \Fieldset::forge('post_form', array('form_attributes' => array('class' => 'form-horizontal')));
        $form->add_model('Model_Post');
        $form->add('add', '', array(
            'type' => 'submit',
            'value' => ($isUpdate) ? __('backend.edit') : __('backend.add'),
            'class' => 'btn btn-primary')
        );

        // Get or create the post
		if ($isUpdate)
		{
			$this->data['post'] = $post = \Model_Post::find($id);
	    	$this->dataGlobal['pageTitle'] = __('backend.post.edit');
		}
		else
		{
			$this->data['post'] = $post = \Model_Post::forge();
	    	$this->dataGlobal['pageTitle'] = __('backend.post.add');
		}

		$form->populate($post);

		// If POST submit
		if (\Input::post('add'))
		{
			$form->validation()->run();

			if( ! $form->validation()->error())
			{
				$post->from_array(array(
					'name' => $form->validated('name'),
					'slug' => ($form->validated('slug') != '') ? \Inflector::friendly_title($form->validated('slug')) : \Inflector::friendly_title($form->validated('name')),
					'category_id' => $form->validated('category_id'),
					'user_id' => $form->validated('user_id'),
					'content' => $form->validated('content'),
				));

				if ($post->save())
				{
					if ($isUpdate)
						\Messages::success(__('backend.post.edited'));
					else
						\Messages::success(__('backend.post.added'));

					\Response::redirect_back('/backend/post');
				}
				else
				{
					\Messages::error(__('error'));
				}
			}
			else
			{
				// Output validation errors		
				foreach ($form->validation()->error() as $error)
				{
					\Messages::error($error);
				}
			}
		}

		$form->repopulate();
		$this->data['form'] = $form;

		$this->theme->set_partial('content', 'backend/post/add')->set($this->data, null, false);
    }

    public function action_delete($id = null)
    {
        $post = \Model_Post::find($id);
        
        if ($post->delete())
        {
            \Messages::success(__('backend.post.deleted'));
        }
        else
        {
            \Messages::error(__('error'));
        }

        \Response::redirect_back('/backend/post');
    }
}
<commit_msg>[UPDATE] post_count update after post save<commit_after><?php

class Controller_Backend_Post extends \Controller_Base_Backend
{

    public function action_index()
    {
    	$this->dataGlobal['pageTitle'] = __('backend.post.manage');
    	$this->data['posts'] = \Model_Post::find('all');
		$this->theme->set_partial('content', 'backend/post/index')->set($this->data); 
    }

    public function action_add($id = null)
    {
        $this->data['isUpdate'] = $isUpdate = ($id !== null) ? true : false;

        // Prepare form fieldset
        $form = \Fieldset::forge('post_form', array('form_attributes' => array('class' => 'form-horizontal')));
        $form->add_model('Model_Post');
        $form->add('add', '', array(
            'type' => 'submit',
            'value' => ($isUpdate) ? __('backend.edit') : __('backend.add'),
            'class' => 'btn btn-primary')
        );

        // Get or create the post
		if ($isUpdate)
		{
			$this->data['post'] = $post = \Model_Post::find($id);
	    	$this->dataGlobal['pageTitle'] = __('backend.post.edit');
		}
		else
		{
			$this->data['post'] = $post = \Model_Post::forge();
	    	$this->dataGlobal['pageTitle'] = __('backend.post.add');
		}

		$form->populate($post);

		// If POST submit
		if (\Input::post('add'))
		{
			$form->validation()->run();

			if ( ! $form->validation()->error())
			{
				$post->from_array(array(
					'name' => $form->validated('name'),
					'slug' => ($form->validated('slug') != '') ? \Inflector::friendly_title($form->validated('slug')) : \Inflector::friendly_title($form->validated('name')),
					'category_id' => $form->validated('category_id'),
					'user_id' => $form->validated('user_id'),
					'content' => $form->validated('content'),
				));

				if ($post->save())
				{
					// Category Post count update
					foreach(\Model_Category::find('all') as $category)
					{
						$category->post_count = count($category->posts);
						$category->save();
					}

					if ($isUpdate)
						\Messages::success(__('backend.post.edited'));
					else
						\Messages::success(__('backend.post.added'));

					\Response::redirect_back('/backend/post');
				}
				else
				{
					\Messages::error(__('error'));
				}
			}
			else
			{
				// Output validation errors		
				foreach ($form->validation()->error() as $error)
				{
					\Messages::error($error);
				}
			}
		}

		$form->repopulate();
		$this->data['form'] = $form;

		$this->theme->set_partial('content', 'backend/post/add')->set($this->data, null, false);
    }

    public function action_delete($id = null)
    {
        $post = \Model_Post::find($id);
        
        if ($post->delete())
        {
            \Messages::success(__('backend.post.deleted'));
        }
        else
        {
            \Messages::error(__('error'));
        }

        \Response::redirect_back('/backend/post');
    }
}

{'fraction_non_alphanumeric': 0.2129898403483309, 'fraction_numerical': 0.0, 'mean_word_length': 2.7350948509485096, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 98, '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': '6335428', 'n_tokens_mistral': 2054, 'n_tokens_neox': 1761, 'n_words': 259}