<commit_before><?php
namespace AnhNhan\Converge\Modules\Task\Controllers;

use AnhNhan\Converge as cv;
use AnhNhan\Converge\Views\Web\Response\ResponseHtml404;
use AnhNhan\Converge\Web\Application\HtmlPayload;
use YamwLibs\Libs\Html\Markup\MarkupContainer;

use AnhNhan\Converge\Modules\Task\Storage\TaskTransaction;
use AnhNhan\Converge\Modules\Task\Transaction\TaskEditor;
use AnhNhan\Converge\Storage\Transaction\TransactionEditor;
use AnhNhan\Converge\Storage\Transaction\TransactionEntity;

use AnhNhan\Converge\Views\Form\FormView;
use AnhNhan\Converge\Views\Form\Controls\SelectControl;
use AnhNhan\Converge\Views\Form\Controls\SubmitControl;
use AnhNhan\Converge\Views\Form\Controls\TextAreaControl;
use AnhNhan\Converge\Views\Form\Controls\TextControl;
use AnhNhan\Converge\Views\Grid\Grid;
use AnhNhan\Converge\Views\Panel\Panel;

use Symfony\Component\HttpFoundation\RedirectResponse;

/**
 * @author <NAME> <<EMAIL>>
 */
final class TaskEdit extends AbstractTaskController
{
    public function handle()
    {
        $request = $this->request;
        $requestMethod = $request->getMethod();
        $query = $this->buildQuery();

        $task = $this->retrieveTaskObject($request, $query);
        if (!$task)
        {
            return id(new ResponseHtml404)->setText('This is not the task you are looking for.');
        }
        $user_query = create_user_query($this->externalApp('user'));
        fetch_external_authors([$task], $user_query, 'assignedId', 'setAssigned', 'assigned');

        $priorities = mkey($query->retrieveTaskPriorities(), 'label_canonical');
        $statuses   = mkey($query->retrieveTaskStatus(), 'label_canonical');

        $container = new MarkupContainer;

        $errors = [];

        $task_uid = $task->uid;
        $task_label = $task->label;
        $task_assigned = $task->assignedId ? $task->assigned->canonical_name : null;
        $task_status = $task->status ? $task->status->label_canonical : null;
        $task_priority = $task->priority ? $task->priority->label_canonical : null;
        $task_description = $task->description;

        if ($requestMethod == 'POST')
        {
            $task_label = trim($request->request->get('label'));
            $task_description = trim($request->request->get('description'));

            $task_assigned = trim($request->request->get('assigned'));
            $task_assigned = to_canonical($task_assigned);

            $task_priority = trim($request->request->get('priority'));
            $task_priority = to_canonical($task_priority);

            $task_status = trim($request->request->get('status'));
            $task_status = to_canonical($task_status);

            $task_label_canonical = to_canonical($task_label);

            if (!strlen($task_label))
            {
                $errors[] = 'We require a descriptive label';
            }
            else if (strlen($task_label_canonical) < 3)
            {
                $errors[] = 'Label is too short to be of any significance.';
            }

            if (!isset($priorities[$task_priority]))
            {
                $errors[] = 'Invalid task priority';
            }

            if (!isset($statuses[$task_status]))
            {
                $errors[] = 'Invalid task status';
            }

            $task_assigned_object = idx($user_query->retrieveUsersForCanonicalNames([$task_assigned]), 0);
            if ($task_assigned && !$task_assigned_object)
            {
                $errors[] = cv\hsprintf(
                    'Could not find the user %s',
                    tooltip('span', '@' . $task_assigned, 'user not found')->addClass('bad-username')
                );
            }

            if (!$errors)
            {
                $task_priority_object = $priorities[$task_priority];
                $task_status_object   = $statuses[$task_status];

                $em = $this->app->getEntityManager();

                $editor = TaskEditor::create($em)
                    ->setActor($this->user->uid)
                    ->setEntity($task)
                    ->setBehaviourOnNoEffect(TransactionEditor::NO_EFFECT_SKIP)
                ;<commit_msg>Fixing a bug where we would not find a user<commit_after><?php
namespace AnhNhan\Converge\Modules\Task\Controllers;

use AnhNhan\Converge as cv;
use AnhNhan\Converge\Views\Web\Response\ResponseHtml404;
use AnhNhan\Converge\Web\Application\HtmlPayload;
use YamwLibs\Libs\Html\Markup\MarkupContainer;

use AnhNhan\Converge\Modules\Task\Storage\TaskTransaction;
use AnhNhan\Converge\Modules\Task\Transaction\TaskEditor;
use AnhNhan\Converge\Storage\Transaction\TransactionEditor;
use AnhNhan\Converge\Storage\Transaction\TransactionEntity;

use AnhNhan\Converge\Views\Form\FormView;
use AnhNhan\Converge\Views\Form\Controls\SelectControl;
use AnhNhan\Converge\Views\Form\Controls\SubmitControl;
use AnhNhan\Converge\Views\Form\Controls\TextAreaControl;
use AnhNhan\Converge\Views\Form\Controls\TextControl;
use AnhNhan\Converge\Views\Grid\Grid;
use AnhNhan\Converge\Views\Panel\Panel;

use Symfony\Component\HttpFoundation\RedirectResponse;

/**
 * @author <NAME> <<EMAIL>>
 */
final class TaskEdit extends AbstractTaskController
{
    public function handle()
    {
        $request = $this->request;
        $requestMethod = $request->getMethod();
        $query = $this->buildQuery();

        $task = $this->retrieveTaskObject($request, $query);
        if (!$task)
        {
            return id(new ResponseHtml404)->setText('This is not the task you are looking for.');
        }
        $user_query = create_user_query($this->externalApp('user'));
        fetch_external_authors([$task], $user_query, 'assignedId', 'setAssigned', 'assigned');

        $priorities = mkey($query->retrieveTaskPriorities(), 'label_canonical');
        $statuses   = mkey($query->retrieveTaskStatus(), 'label_canonical');

        $container = new MarkupContainer;

        $errors = [];

        $task_uid = $task->uid;
        $task_label = $task->label;
        $task_assigned = $task->assignedId ? $task->assigned->canonical_name : null;
        $task_status = $task->status ? $task->status->label_canonical : null;
        $task_priority = $task->priority ? $task->priority->label_canonical : null;
        $task_description = $task->description;

        if ($requestMethod == 'POST')
        {
            $task_label = trim($request->request->get('label'));
            $task_description = trim($request->request->get('description'));

            $task_assigned = trim($request->request->get('assigned'));
            $task_assigned = to_canonical($task_assigned);

            $task_priority = trim($request->request->get('priority'));
            $task_priority = to_canonical($task_priority);

            $task_status = trim($request->request->get('status'));
            $task_status = to_canonical($task_status);

            $task_label_canonical = to_canonical($task_label);

            if (!strlen($task_label))
            {
                $errors[] = 'We require a descriptive label';
            }
            else if (strlen($task_label_canonical) < 3)
            {
                $errors[] = 'Label is too short to be of any significance.';
            }

            if (!isset($priorities[$task_priority]))
            {
                $errors[] = 'Invalid task priority';
            }

            if (!isset($statuses[$task_status]))
            {
                $errors[] = 'Invalid task status';
            }

            $task_assigned_object = head($user_query->retrieveUsersForCanonicalNames([$task_assigned]));
            if ($task_assigned && !$task_assigned_object)
            {
                $errors[] = cv\hsprintf(
                    'Could not find the user %s',
                    tooltip('span', '@' . $task_assigned, 'user not found')->addClass('bad-username')
                );
            }

            if (!$errors)
            {
                $task_priority_object = $priorities[$task_priority];
                $task_status_object   = $statuses[$task_status];

                $em = $this->app->getEntityManager();

                $editor = TaskEditor::create($em)
                    ->setActor($this->user->uid)
                    ->setEntity($task)
                    ->setBehaviourOnNoEffect(TransactionEditor::NO_EFFECT_SKIP)
                ;
{'fraction_non_alphanumeric': 0.13359598853868196, 'fraction_numerical': 0.0017908309455587394, 'mean_word_length': 2.5035549979088247, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 87, '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': '2650220', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2387, 'n_words': 392}