Importer/PKP/SectionImporter.php
public function importJournalSections($oldJournalId, $newJournalId)
    {
        $this->consoleOutput->writeln("Importing journal's sections...");

        $sectionsSql = "SELECT * FROM sections WHERE journal_id = :id";
        $sectionsStatement = $this->dbalConnection->prepare($sectionsSql);
        $sectionsStatement->bindValue('id', $oldJournalId);
        $sectionsStatement->execute();
        $sections = $sectionsStatement->fetchAll();

        try {
            $this->em->beginTransaction();
            $createdSections = array();
            $createdSectionIds = array();
            $persistCounter = 0;

            foreach ($sections as $section) {
                $createdSection = $this->importSection($section['section_id'], $newJournalId);
                $createdSections[$section['section_id']] = $createdSection;
                $persistCounter++;

                if ($persistCounter % 10 == 0 || $persistCounter == count($sections)) {
                    $this->consoleOutput->writeln("Writing sections...", true);
                    $this->em->flush();
                    $this->em->commit();
                    $this->em->clear();
                    $this->em->beginTransaction();

                    /** @var Section $entity */
                    foreach ($createdSections as $oldSectionId => $entity) {
                        $createdSectionIds[$oldSectionId] = $entity->getId();
                        $map = new ImportMap($oldSectionId, $entity->getId(), Section::class);
                        $this->em->persist($map);
                    }

                    $this->em->flush();
                    $createdSections = [];
                }
            }

            $this->em->commit();
        }  catch (Exception $exception) {
            $this->em->rollback();
            throw $exception;
        }

        return $createdSectionIds;
    }
public function importJournalSections($oldJournalId, $newJournalId)
    {
        $this->consoleOutput->writeln("Importing journal's sections...");

        $sectionsSql = "SELECT * FROM sections WHERE journal_id = :id";
        $sectionsStatement = $this->dbalConnection->prepare($sectionsSql);
        $sectionsStatement->bindValue('id', $oldJournalId);
        $sectionsStatement->execute();
        $sections = $sectionsStatement->fetchAll();

        try {
            $this->em->beginTransaction();
            $createdSections = array();
            $createdSectionIds = array();
            $persistCounter = 0;

            foreach ($sections as $section) {
                $createdSection = $this->importSection($section['section_id'], $newJournalId);
                $createdSections[$section['section_id']] = $createdSection;
                $persistCounter++;

                if ($persistCounter % 10 == 0 || $persistCounter == count($sections)) {
                    $this->consoleOutput->writeln("Writing sections...", true);
                    $this->em->flush();
                    $this->em->commit();
                    $this->em->clear();
                    $this->em->beginTransaction();

                    /** @var Section $entity */
                    foreach ($createdSections as $oldSectionId => $entity) {
                        $createdSectionIds[$oldSectionId] = $entity->getId();
                        $map = new ImportMap($oldSectionId, $entity->getId(), Section::class);
                        $this->em->persist($map);
                    }

                    $this->em->flush();
                    $createdSections = [];
                }
            }

            $this->em->commit();
        }  catch (Exception $exception) {
            $this->em->rollback();
            throw $exception;
        }

        return $createdSectionIds;
    }
public function importJournalSections ( $ oldJournalId , $ newJournalId ) { $ this -> consoleOutput -> writeln ( "Importing journal's sections..." ) ; $ sectionsSql = "SELECT * FROM sections WHERE journal_id = :id" ; $ sectionsStatement = $ this -> dbalConnection -> prepare ( $ sectionsSql ) ; $ sectionsStatement -> bindValue ( 'id' , $ oldJournalId ) ; $ sectionsStatement -> execute ( ) ; $ sections = $ sectionsStatement -> fetchAll ( ) ; try { $ this -> em -> beginTransaction ( ) ; $ createdSections = array ( ) ; $ createdSectionIds = array ( ) ; $ persistCounter = 0 ; foreach ( $ sections as $ section ) { $ createdSection = $ this -> importSection ( $ section [ 'section_id' ] , $ newJournalId ) ; $ createdSections [ $ section [ 'section_id' ] ] = $ createdSection ; $ persistCounter ++ ; if ( $ persistCounter % 10 == 0 || $ persistCounter == count ( $ sections ) ) { $ this -> consoleOutput -> writeln ( "Writing sections..." , true ) ; $ this -> em -> flush ( ) ; $ this -> em -> commit ( ) ; $ this -> em -> clear ( ) ; $ this -> em -> beginTransaction ( ) ; /** @var Section $entity */ foreach ( $ createdSections as $ oldSectionId => $ entity ) { $ createdSectionIds [ $ oldSectionId ] = $ entity -> getId ( ) ; $ map = new ImportMap ( $ oldSectionId , $ entity -> getId ( ) , Section :: class ) ; $ this -> em -> persist ( $ map ) ; } $ this -> em -> flush ( ) ; $ createdSections = [ ] ; } } $ this -> em -> commit ( ) ; } catch ( Exception $ exception ) { $ this -> em -> rollback ( ) ; throw $ exception ; } return $ createdSectionIds ; }
Imports sections of the given journal.
@param int $oldJournalId Section's old Journal ID
@param int $newJournalId Section's new Journal ID
@return array An array whose keys are old IDs and values are new IDs
@throws Exception
@throws \Doctrine\DBAL\DBALException
Imports sections of the given journal .