<commit_before><?php

namespace Bolt\Storage\Repository;

use Bolt\Events\HydrationEvent;
use Bolt\Events\StorageEvents;
use Bolt\Storage\ContentLegacyService;
use Bolt\Storage\Repository;

/**
 * A Repository class that handles dynamically created content tables.
 */
class ContentRepository extends Repository
{
    /** @var ContentLegacyService */
    protected $legacy;

    /**
     * Fetches details on records for select lists.
     *
     * @param string $contentType
     * @param string $order
     *
     * @return \Bolt\Storage\Entity\Cron
     */
    public function getSelectList($contentType, $order)
    {
        $query = $this->querySelectList($contentType, $order);

        return $query->execute()->fetchAll();
    }

    /**
     * Build the query for a record select list.
     *
     * @param string $contentType
     * @param string $order
     *
     * @return QueryBuilder
     */
    public function querySelectList($contentType, $order)
    {
        if (strpos($order, '-') === 0) {
            $direction = 'ASC';
            $order = ltrim($order, '-');
        } else {
            $direction = 'DESC';
        }

        $qb = $this->createQueryBuilder($contentType);
        $qb->select('id, ' . $this->getTitleColumnName() . ' as title')
            ->orderBy($order, $direction)
        ;

        return $qb;
    }

    /**
     * Set the legacy Content service object.
     *
     * @param ContentLegacyService $service
     */
    public function setLegacyService(ContentLegacyService $service)
    {
        $this->legacy = $service;
        $this->event()->addListener(StorageEvents::PRE_HYDRATE, [$this, 'hydrateLegacyHandler']);
    }

    /**
     * {@inheritdoc}
     */
    public function createQueryBuilder($alias = 'content')
    {
        return parent::createQueryBuilder($alias);
    }

    /**
     * Hydration handler for the legacy object.
     *
     * @param HydrationEvent $event
     */
    public function hydrateLegacyHandler(HydrationEvent $event)
    {
        $entity = $event->getArgument('entity');
        var_dump($entity);
        $entity->setLegacyService($this->legacy);
    }

    /**
     * Get the likely column name of the title.
     *
     * @return array
     */
    protected function getTitleColumnName()
    {
        $names = [
            'title', 'name', 'caption', 'subject', // EN
            'titel', 'naam', 'onderwerp',          // NL
            'nom', 'sujet',                        // FR
            'nombre', 'sujeto'                     // ES
        ];
<commit_msg>remove accidental debug<commit_after><?php

namespace Bolt\Storage\Repository;

use Bolt\Events\HydrationEvent;
use Bolt\Events\StorageEvents;
use Bolt\Storage\ContentLegacyService;
use Bolt\Storage\Repository;

/**
 * A Repository class that handles dynamically created content tables.
 */
class ContentRepository extends Repository
{
    /** @var ContentLegacyService */
    protected $legacy;

    /**
     * Fetches details on records for select lists.
     *
     * @param string $contentType
     * @param string $order
     *
     * @return \Bolt\Storage\Entity\Cron
     */
    public function getSelectList($contentType, $order)
    {
        $query = $this->querySelectList($contentType, $order);

        return $query->execute()->fetchAll();
    }

    /**
     * Build the query for a record select list.
     *
     * @param string $contentType
     * @param string $order
     *
     * @return QueryBuilder
     */
    public function querySelectList($contentType, $order)
    {
        if (strpos($order, '-') === 0) {
            $direction = 'ASC';
            $order = ltrim($order, '-');
        } else {
            $direction = 'DESC';
        }

        $qb = $this->createQueryBuilder($contentType);
        $qb->select('id, ' . $this->getTitleColumnName() . ' as title')
            ->orderBy($order, $direction)
        ;

        return $qb;
    }

    /**
     * Set the legacy Content service object.
     *
     * @param ContentLegacyService $service
     */
    public function setLegacyService(ContentLegacyService $service)
    {
        $this->legacy = $service;
        $this->event()->addListener(StorageEvents::PRE_HYDRATE, [$this, 'hydrateLegacyHandler']);
    }

    /**
     * {@inheritdoc}
     */
    public function createQueryBuilder($alias = 'content')
    {
        return parent::createQueryBuilder($alias);
    }

    /**
     * Hydration handler for the legacy object.
     *
     * @param HydrationEvent $event
     */
    public function hydrateLegacyHandler(HydrationEvent $event)
    {
        $entity = $event->getArgument('entity');
        $entity->setLegacyService($this->legacy);
    }

    /**
     * Get the likely column name of the title.
     *
     * @return array
     */
    protected function getTitleColumnName()
    {
        $names = [
            'title', 'name', 'caption', 'subject', // EN
            'titel', 'naam', 'onderwerp',          // NL
            'nom', 'sujet',                        // FR
            'nombre', 'sujeto'                     // ES
        ];

{'fraction_non_alphanumeric': 0.13315057763853536, 'fraction_numerical': 0.00039161934599569217, 'mean_word_length': 2.051373954599761, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '1450268', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1452, 'n_words': 327}