<commit_before><?php
namespace Crud\Action\Bulk;

use Cake\Event\Event;
use Cake\Network\Exception\BadRequestException;
use Cake\ORM\Query;
use Cake\Utility\Hash;
use Crud\Action\BaseAction as CrudBaseAction;
use Crud\Event\Subject;
use Crud\Traits\RedirectTrait;

/**
 * Handles 'Bulk' Crud actions
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 */
abstract class BaseAction extends CrudBaseAction
{
    use RedirectTrait;

    /**
     * Default settings for 'base' actions
     *
     * @var array
     */
    protected $_defaultConfig = [
        'enabled' => true,
        'scope' => 'bulk',
        'findMethod' => 'all',
        'actionName' => 'Bulk',
        'messages' => [
            'success' => [
                'text' => 'Bulk action successfully completed'
            ],
            'error' => [
                'text' => 'Could not complete bulk action'
            ]
        ],
    ];

    /**
     * Handle a bulk event
     *
     * @return \Cake\Network\Response
     */
    protected function _handle()
    {
        $ids = $this->_controller()->request->data('id');
        if (!is_array($ids) || !Hash::numeric(array_keys($ids))) {
            throw new BadRequestException('Bad request data');
        }
        $ids = array_filter($ids);

        $subject = $this->_subject();
        $subject->set(['ids' => $ids]);

        $actionName = $this->config('actionName');

        $this->_trigger(sprintf('before%sFind', $actionName), $subject);
        $query = $this->_table()->find($this->config('findMethod'), $this->_getFindConfig($subject));
        $subject->set(['query' => $query]);

        $this->_trigger(sprintf('after%sFind', $actionName), $subject);

        $event = $this->_trigger(sprintf('before%s', $actionName), $subject);
        if ($event->isStopped()) {
            return $this->_stopped($subject);
        }<commit_msg>Add the ability to set all incoming ids to true for a given action<commit_after><?php
namespace Crud\Action\Bulk;

use Cake\Event\Event;
use Cake\Network\Exception\BadRequestException;
use Cake\ORM\Query;
use Cake\Utility\Hash;
use Crud\Action\BaseAction as CrudBaseAction;
use Crud\Event\Subject;
use Crud\Traits\RedirectTrait;

/**
 * Handles 'Bulk' Crud actions
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 */
abstract class BaseAction extends CrudBaseAction
{
    use RedirectTrait;

    /**
     * Default settings for 'base' actions
     *
     * @var array
     */
    protected $_defaultConfig = [
        'enabled' => true,
        'scope' => 'bulk',
        'findMethod' => 'all',
        'actionName' => 'Bulk',
        'messages' => [
            'success' => [
                'text' => 'Bulk action successfully completed'
            ],
            'error' => [
                'text' => 'Could not complete bulk action'
            ]
        ],
    ];

    /**
     * Handle a bulk event
     *
     * @return \Cake\Network\Response
     */
    protected function _handle()
    {
        $ids = $this->_controller()->request->data('id');

        $all = false;
        if (is_array($ids)) {
            $all = Hash::get((array)$ids, '_all', false);
            unset($ids['_all']);
        }

        if (!is_array($ids) || !Hash::numeric(array_keys($ids))) {
            throw new BadRequestException('Bad request data');
        }

        if ($all) {
            foreach ($ids as $key => $value) {
                $ids[$key] = 1;
            }
        }

        $ids = array_filter($ids);

        $subject = $this->_subject();
        $subject->set(['ids' => $ids]);

        $actionName = $this->config('actionName');

        $this->_trigger(sprintf('before%sFind', $actionName), $subject);
        $query = $this->_table()->find($this->config('findMethod'), $this->_getFindConfig($subject));
        $subject->set(['query' => $query]);

        $this->_trigger(sprintf('after%sFind', $actionName), $subject);

        $event = $this->_trigger(sprintf('before%s', $actionName), $subject);
        if ($event->isStopped()) {
            return $this->_stopped($subject);
        }
{'fraction_non_alphanumeric': 0.16076099881093936, 'fraction_numerical': 0.00023781212841854935, 'mean_word_length': 2.317034700315457, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, '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': '6790781', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1219, 'n_words': 275}