<commit_before><?php
/**
 * Wasabi CMS
 * Copyright (c) <NAME> (http://frankfoerster.com)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) <NAME> (http://frankfoerster.com)
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */
namespace Wasabi\Core\Model\Table;

use ArrayObject;
use Cake\Cache\Cache;
use Cake\Datasource\ResultSetInterface;
use Cake\Event\Event;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Wasabi\Core\Model\Entity\Route;

/**
 * Class RoutesTable
 */
class RoutesTable extends Table
{
    /**
     * Initialize a table instance. Called after the constructor.
     *
     * @param array $config Configuration options passed to the constructor.
     * @return void
     */
    public function initialize(array $config)
    {
        $this->addBehavior('Timestamp');
    }

    /**
     * Default validation rules.
     *
     * @param Validator $validator The validator to customize.
     * @return Validator
     */
    public function validationDefault(Validator $validator)
    {
        return $validator
            ->notEmpty('url', __d('wasabi_core', 'Please enter a url for this route.'));
    }

    /**
     * Build Rules.
     *
     * @param RulesChecker $rules The rules checker to customize.
     * @return RulesChecker
     */
    public function buildRules(RulesChecker $rules)
    {
        $rules->add($rules->isUnique(['url'], __d('wasabi_core', 'This url is already taken.')));
        return $rules;
    }

    /**
     * Called after an entity is saved.
     *
     * @param Event $event An event instance.
     * @param Route $entity The entity that triggered the event.
     * @param ArrayObject $options Additional options passed to the save call.
     * @return void
     */
    public function afterSave(Event $event, Route $entity, ArrayObject $options)
    {
        Cache::clearGroup('wasabi/core/routes');
        $this->eventManager()->dispatch(new Event('Wasabi.Routes.changed'));
    }

    /**
     * Check wheter a route with the given $url already exists.
     *
     * @param string $url The url to check.
     * @return bool
     */
    public function routeAlreadyExists($url)<commit_msg>fix cache clearing for the wasabi/core/routes cache<commit_after><?php
/**
 * Wasabi CMS
 * Copyright (c) <NAME> (http://frankfoerster.com)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) <NAME> (http://frankfoerster.com)
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */
namespace Wasabi\Core\Model\Table;

use ArrayObject;
use Cake\Cache\Cache;
use Cake\Datasource\ResultSetInterface;
use Cake\Event\Event;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Wasabi\Core\Model\Entity\Route;

/**
 * Class RoutesTable
 */
class RoutesTable extends Table
{
    /**
     * Initialize a table instance. Called after the constructor.
     *
     * @param array $config Configuration options passed to the constructor.
     * @return void
     */
    public function initialize(array $config)
    {
        $this->addBehavior('Timestamp');
    }

    /**
     * Default validation rules.
     *
     * @param Validator $validator The validator to customize.
     * @return Validator
     */
    public function validationDefault(Validator $validator)
    {
        return $validator
            ->notEmpty('url', __d('wasabi_core', 'Please enter a url for this route.'));
    }

    /**
     * Build Rules.
     *
     * @param RulesChecker $rules The rules checker to customize.
     * @return RulesChecker
     */
    public function buildRules(RulesChecker $rules)
    {
        $rules->add($rules->isUnique(['url'], __d('wasabi_core', 'This url is already taken.')));
        return $rules;
    }

    /**
     * Called after an entity is saved.
     *
     * @param Event $event An event instance.
     * @param Route $entity The entity that triggered the event.
     * @param ArrayObject $options Additional options passed to the save call.
     * @return void
     */
    public function afterSave(Event $event, Route $entity, ArrayObject $options)
    {
        Cache::clear(false, 'wasabi/core/routes');
        $this->eventManager()->dispatch(new Event('Wasabi.Routes.changed'));
    }

    /**
     * Check wheter a route with the given $url already exists.
     *
     * @param string $url The url to check.
     * @return bool
     */
    public function routeAlreadyExists($url)
{'fraction_non_alphanumeric': 0.1138900372054568, 'fraction_numerical': 0.0, 'mean_word_length': 2.792319749216301, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1761355', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1359, 'n_words': 422}