コード例 #1
0
 function handleSectionNode(&$journal, &$sectionNode, &$issue, &$errors, &$user, $isCommandLine, &$dependentItems, $sectionIndex = null)
 {
     $sectionDao =& DAORegistry::getDAO('SectionDAO');
     $errors = array();
     $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames());
     // => journal locales must be set up before
     $journalPrimaryLocale = $journal->getPrimaryLocale();
     // The following page or two is responsible for locating an
     // existing section based on title and/or abbrev, or, if none
     // can be found, creating a new one.
     $titles = array();
     for ($index = 0; $node = $sectionNode->getChildByName('title', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $journalPrimaryLocale;
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.sectionTitleLocaleUnsupported', array('sectionTitle' => $node->getValue(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
             // or ignore this error?
         }
         $titles[$locale] = $node->getValue();
     }
     if (empty($titles)) {
         $errors[] = array('plugins.importexport.native.import.error.sectionTitleMissing', array('issueTitle' => $issue->getIssueIdentification()));
         return false;
     }
     $abbrevs = array();
     for ($index = 0; $node = $sectionNode->getChildByName('abbrev', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $journalPrimaryLocale;
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.sectionAbbrevLocaleUnsupported', array('sectionAbbrev' => $node->getValue(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
             // or ignore this error?
         }
         $abbrevs[$locale] = $node->getValue();
     }
     $identifyTypes = array();
     for ($index = 0; $node = $sectionNode->getChildByName('identify_type', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $journalPrimaryLocale;
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.sectionIdentifyTypeLocaleUnsupported', array('sectionIdentifyType' => $node->getValue(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
             // or ignore this error?
         }
         $identifyTypes[$locale] = $node->getValue();
     }
     $policies = array();
     for ($index = 0; $node = $sectionNode->getChildByName('policy', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $journalPrimaryLocale;
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.sectionPolicyLocaleUnsupported', array('sectionPolicy' => $node->getValue(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
             // or ignore this error?
         }
         $policies[$locale] = $node->getValue();
     }
     // $title and, optionally, $abbrev contain information that can
     // be used to locate an existing section. Otherwise, we'll
     // create a new one. If $title and $abbrev each match an
     // existing section, but not the same section, throw an error.
     $section = null;
     $foundSectionId = $foundSectionTitle = null;
     $index = 0;
     foreach ($titles as $locale => $title) {
         $section = $sectionDao->getSectionByTitle($title, $journal->getId());
         if ($section) {
             $sectionId = $section->getId();
             if ($foundSectionId) {
                 if ($foundSectionId != $sectionId) {
                     // Mismatching sections found. Throw an error.
                     $errors[] = array('plugins.importexport.native.import.error.sectionTitleMismatch', array('section1Title' => $title, 'section2Title' => $foundSectionTitle, 'issueTitle' => $issue->getIssueIdentification()));
                     return false;
                 }
             } else {
                 if ($index > 0) {
                     // the current title matches, but the prev titles didn't => error
                     $errors[] = array('plugins.importexport.native.import.error.sectionTitleMatch', array('sectionTitle' => $title, 'issueTitle' => $issue->getIssueIdentification()));
                     return false;
                 }
             }
             $foundSectionId = $sectionId;
             $foundSectionTitle = $title;
         } else {
             if ($foundSectionId) {
                 // a prev title matched, but the current doesn't => error
                 $errors[] = array('plugins.importexport.native.import.error.sectionTitleMatch', array('sectionTitle' => $foundSectionTitle, 'issueTitle' => $issue->getIssueIdentification()));
                 return false;
             }
         }
         $index++;
     }
     // check abbrevs:
     $abbrevSection = null;
     $foundSectionId = $foundSectionAbbrev = null;
     $index = 0;
     foreach ($abbrevs as $locale => $abbrev) {
         $abbrevSection = $sectionDao->getSectionByAbbrev($abbrev, $journal->getId());
         if ($abbrevSection) {
             $sectionId = $abbrevSection->getSectionId();
             if ($foundSectionId) {
                 if ($foundSectionId != $sectionId) {
                     // Mismatching sections found. Throw an error.
                     $errors[] = array('plugins.importexport.native.import.error.sectionAbbrevMismatch', array('section1Abbrev' => $abbrev, 'section2Abbrev' => $foundSectionAbbrev, 'issueTitle' => $issue->getIssueIdentification()));
                     return false;
                 }
             } else {
                 if ($index > 0) {
                     // the current abbrev matches, but the prev abbrevs didn't => error
                     $errors[] = array('plugins.importexport.native.import.error.sectionAbbrevMatch', array('sectionAbbrev' => $sectionAbbrev, 'issueTitle' => $issue->getIssueIdentification()));
                     return false;
                 }
             }
             $foundSectionId = $sectionId;
             $foundSectionAbbrev = $abbrev;
         } else {
             if ($foundSectionId) {
                 // a prev abbrev matched, but the current doesn't => error
                 $errors[] = array('plugins.importexport.native.import.error.sectionAbbrevMatch', array('sectionAbbrev' => $foundSectionAbbrev, 'issueTitle' => $issue->getIssueIdentification()));
                 return false;
             }
         }
         $index++;
     }
     if (!$section && !$abbrevSection) {
         // The section was not matched. Create one.
         // Note that because sections are global-ish,
         // we're not maintaining a list of created
         // sections to delete in case the import fails.
         unset($section);
         $section = new Section();
         $section->setTitle($titles, null);
         $section->setAbbrev($abbrevs, null);
         $section->setIdentifyType($identifyTypes, null);
         $section->setPolicy($policies, null);
         $section->setJournalId($journal->getId());
         $section->setSequence(REALLY_BIG_NUMBER);
         $section->setMetaIndexed(1);
         $section->setEditorRestricted(1);
         $section->setSectionId($sectionDao->insertSection($section));
         $sectionDao->resequenceSections($journal->getId());
     }
     if (!$section && $abbrevSection) {
         unset($section);
         $section =& $abbrevSection;
     }
     // $section *must* now contain a valid section, whether it was
     // found amongst existing sections or created anew.
     // Handle custom ordering, if necessary.
     if ($sectionIndex !== null) {
         $sectionDao->insertCustomSectionOrder($issue->getId(), $section->getId(), $sectionIndex);
     }
     $hasErrors = false;
     for ($index = 0; $node = $sectionNode->getChildByName('article', $index); $index++) {
         if (!NativeImportDom::handleArticleNode($journal, $node, $issue, $section, $article, $publishedArticle, $articleErrors, $user, $isCommandLine, $dependentItems)) {
             $errors = array_merge($errors, $articleErrors);
             $hasErrors = true;
         }
     }
     if ($hasErrors) {
         return false;
     }
     return true;
 }