<commit_before><?php

namespace Echo511\TreeTraversal\Operations;

use Echo511\TreeTraversal\Tree;
use FluentLiteral;

abstract class Base
{

    const INDEX_LFT = 'lft';
    const INDEX_RGT = 'rgt';

    /**
     * Indexed and depth of target node.
     * @var array
     */
    protected $target = [];

    /**
     * @var array
     */
    protected $config = [];

    /**
     * @var Tree
     */
    protected $tree;

    /**
     * @param array $target
     * @param array $config
     * @param Tree $tree
     */
    public function __construct(array $target, array $config, Tree $tree)
    {
        $this->target = $target;
        $this->config = $config;
        $this->tree = $tree;
    }

    /**
     * Run the operation in transaction.
     */
    public function run()
    {
        $this->tree->getFluent()->getPdo()->beginTransaction();
        $this->doRun();
        $this->tree->getFluent()->getPdo()->commit();
    }

    abstract protected function doRun();

    /**
     * IDs of shifting nodes.
     * @return mixed
     */
    protected function getShiftingNodes()
    {
        $limits = $this->getShiftingIndexesLimits();
        return $this->getNodesBetween($limits['min'], $limits['max']);
    }

    /**
     * Get the distance between indexes of shifting nodes.
     * @return type
     */
    protected function getShiftingNodesRange()
    {<commit_msg>Tree : Operations : use table lock<commit_after><?php

namespace Echo511\TreeTraversal\Operations;

use Echo511\TreeTraversal\Tree;
use Exception;
use FluentLiteral;

abstract class Base
{

    const INDEX_LFT = 'lft';
    const INDEX_RGT = 'rgt';

    /**
     * Indexed and depth of target node.
     * @var array
     */
    protected $target = [];

    /**
     * @var array
     */
    protected $config = [];

    /**
     * @var Tree
     */
    protected $tree;

    /**
     * @param array $target
     * @param array $config
     * @param Tree $tree
     */
    public function __construct(array $target, array $config, Tree $tree)
    {
        $this->target = $target;
        $this->config = $config;
        $this->tree = $tree;
    }

    /**
     * Run the operation in transaction.
     */
    public function run()
    {
        $config = $this->config;
        try {
            $this->getFluent()->getPdo()->beginTransaction();
            $this->tree->getFluent()->getPdo()->exec("LOCK TABLES $config[table] WRITE;");
            $this->doRun();
            $this->getFluent()->getPdo()->commit();
            $this->tree->getFluent()->getPdo()->query("UNLOCK TABLES;");
        } catch (Exception $ex) {
            $this->getFluent()->getPdo()->rollBack();
            $this->tree->getFluent()->getPdo()->query("UNLOCK TABLES;");
            throw $ex;
        }
    }

    abstract protected function doRun();

    /**
     * IDs of shifting nodes.
     * @return mixed
     */
    protected function getShiftingNodes()
    {
        $limits = $this->getShiftingIndexesLimits();
        return $this->getNodesBetween($limits['min'], $limits['max']);
    }

    /**
     * Get the distance between indexes of shifting nodes.
     * @return type
     */
    protected function getShiftingNodesRange()
    {
{'fraction_non_alphanumeric': 0.15116640746500778, 'fraction_numerical': 0.0037325038880248835, 'mean_word_length': 2.0952839268527432, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '6055299', 'n_tokens_mistral': 989, 'n_tokens_neox': 952, 'n_words': 221}