<commit_before><?php
namespace Concrete\Core\Backup;

use Concrete\Core\Backup\ContentImporter\Importer\Routine\SpecifiableHomePageRoutineInterface;
use Concrete\Core\File\Importer;
use Concrete\Core\Page\Type\Composer\FormLayoutSetControl;
use Core;

class ContentImporter
{

    protected static $mcBlockIDs = array();
    protected static $ptComposerOutputControlIDs = array();
    protected $home;

    public function importContentFile($file)
    {
        $sx = simplexml_load_file($file);
        $this->import($sx);
    }

    public function setHomePage($c)
    {
        $this->home = $c;
    }

    public function importContentString($string)
    {
        $sx = simplexml_load_string($string);
        $this->import($sx);
    }

    public function importXml(\SimpleXMLElement $xml)
    {
        $this->import($xml);
    }

    protected function import(\SimpleXMLElement $element)
    {
        $manager = Core::make('import/item/manager');
        foreach ($manager->getImporterRoutines() as $routine) {
            if (isset($this->home) && $routine instanceof SpecifiableHomePageRoutineInterface) {
                $home = \Page::getByID($this->home->getCollectionID()); // we always need the most recent version.
                $routine->setHomePage($home);
            }
            $routine->import($element);
            if (isset($this->home) && $routine instanceof SpecifiableHomePageRoutineInterface) {
                // Unset the home page on each item post import
                $routine->setHomePage(null);
            }
        }
    }

    public static function getMasterCollectionTemporaryBlockIDs()
    {
        return self::$mcBlockIDs;
    }

    public static function addMasterCollectionBlockID($b, $id)
    {
        self::$mcBlockIDs[$b->getBlockID()] = $id;
    }

    public static function getMasterCollectionTemporaryBlockID($b)
    {
        if (isset(self::$mcBlockIDs[$b->getBlockID()])) {
            return self::$mcBlockIDs[$b->getBlockID()];
        }
    }

    public static function addPageTypeComposerOutputControlID(FormLayoutSetControl $control, $id)
    {<commit_msg>Improve the contentimporter by clearing the entitymanager regularly (#6011)<commit_after><?php
namespace Concrete\Core\Backup;

use Concrete\Core\Backup\ContentImporter\Importer\Routine\SpecifiableHomePageRoutineInterface;
use Concrete\Core\File\Importer;
use Concrete\Core\Page\Page;
use Concrete\Core\Page\Type\Composer\FormLayoutSetControl;
use Concrete\Core\Support\Facade\Application;
use Core;
use Doctrine\ORM\EntityManagerInterface;

class ContentImporter
{

    protected static $mcBlockIDs = array();
    protected static $ptComposerOutputControlIDs = array();
    protected $home;

    public function importContentFile($file)
    {
        $sx = simplexml_load_file($file);
        $this->import($sx);
    }

    public function setHomePage($c)
    {
        $this->home = $c;
    }

    public function importContentString($string)
    {
        $sx = simplexml_load_string($string);
        $this->import($sx);
    }

    public function importXml(\SimpleXMLElement $xml)
    {
        $this->import($xml);
    }

    protected function import(\SimpleXMLElement $element)
    {
        $app = Application::getFacadeApplication();

        $manager = $app->make('import/item/manager');
        $orm = $app->make(EntityManagerInterface::class);
        foreach ($manager->getImporterRoutines() as $routine) {
            if (isset($this->home) && $routine instanceof SpecifiableHomePageRoutineInterface) {
                $home = Page::getByID($this->home->getCollectionID()); // we always need the most recent version.
                $routine->setHomePage($home);
            }
            $routine->import($element);
            if (isset($this->home) && $routine instanceof SpecifiableHomePageRoutineInterface) {
                // Unset the home page on each item post import
                $routine->setHomePage(null);
            }

            $orm->clear();
        }
    }

    public static function getMasterCollectionTemporaryBlockIDs()
    {
        return self::$mcBlockIDs;
    }

    public static function addMasterCollectionBlockID($b, $id)
    {
        self::$mcBlockIDs[$b->getBlockID()] = $id;
    }

    public static function getMasterCollectionTemporaryBlockID($b)
    {
        if (isset(self::$mcBlockIDs[$b->getBlockID()])) {
            return self::$mcBlockIDs[$b->getBlockID()];
        }
    }

    public static function addPageTypeComposerOutputControlID(FormLayoutSetControl $control, $id)
    {
{'fraction_non_alphanumeric': 0.12029746281714786, 'fraction_numerical': 0.0008748906386701663, 'mean_word_length': 2.872142252328535, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '2874700', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1287, 'n_words': 245}