importXML() public static method

Import a locale XML file.
public static importXML ( SimpleXMLElement $xml, boolean $overwriteConflicts = false, array $frontendLanguages = null, array $backendLanguages = null, integer $userId = null, integer $date = null ) : array
$xml SimpleXMLElement The locale XML.
$overwriteConflicts boolean Should we overwrite when there is a conflict?
$frontendLanguages array The frontend languages to install locale for.
$backendLanguages array The backend languages to install locale for.
$userId integer Id of the user these translations should be inserted for.
$date integer The date the translation has been inserted.
return array The import statistics
Example #1
0
 /**
  * @param string $localePath
  * @param bool $overwrite
  * @param OutputInterFace $output
  * @throws Exception
  */
 private function importLocale($localePath, $overwrite, OutputInterface $output)
 {
     // Load the xml from the file
     $xmlData = @simplexml_load_file($localePath);
     // This is an invalid xml file
     if ($xmlData === false) {
         throw new Exception('Invalid locale.xml file.');
     }
     // Everything ok, let's import the locale
     $results = BackendLocaleModel::importXML($xmlData, $overwrite, null, null, 1);
     if ($results['total'] < 0) {
         $output->writeln('<error>Something went wrong during import.</error>');
         return;
     }
     if ($results['imported'] > 0) {
         $output->writeln('<comment>Imported ' . $results['imported'] . ' translations succesfully!</comment>');
         return;
     }
     if ($results['imported'] == 0) {
         $output->writeln('<info>No locale was imported. Try adding the overwrite (-o) option.</info>');
         return;
     }
 }
Example #2
0
    $baseFile = $options['f'];
    if (!file_exists($baseFile)) {
        throw new Exception('The given file(' . $baseFile . ') does not exist.');
    }
}
// bootstrap Fork
define('APPLICATION', 'Backend');
$kernel = new AppKernel('prod', false);
$kernel->boot();
$kernel->defineForkConstants();
if (!defined('PATH_WWW')) {
    define('PATH_WWW', __DIR__ . '/..');
}
$loader = new BackendInit($kernel);
$loader->initialize('Backend');
$loader->passContainerToModels();
// create needed constants
$container = $kernel->getContainer();
// Set the overwrite parameter
$overwrite = isset($options['o']);
// Set the basedir
$baseDir = getcwd() . '/..';
// load the xml from the file
$xmlData = @simplexml_load_file($baseFile);
// this is an invalid xml file
if ($xmlData === false) {
    throw new Exception('Invalid locale.xml file.');
}
// Everything ok, let's install the locale
BackendLocaleModel::importXML($xmlData, $overwrite, null, null, 1);
Example #3
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // redefine fields
         /** @var $fileFile \SpoonFormFile */
         $fileFile = $this->frm->getField('file');
         $chkOverwrite = $this->frm->getField('overwrite');
         // name checks
         if ($fileFile->isFilled(BL::err('FieldIsRequired'))) {
             // only xml files allowed
             if ($fileFile->isAllowedExtension(array('xml'), sprintf(BL::getError('ExtensionNotAllowed'), 'xml'))) {
                 // load xml
                 $xml = @simplexml_load_file($fileFile->getTempFileName());
                 // invalid xml
                 if ($xml === false) {
                     $fileFile->addError(BL::getError('InvalidXML'));
                 }
             }
         }
         if ($this->frm->isCorrect()) {
             // import
             $statistics = BackendLocaleModel::importXML($xml, $chkOverwrite->getValue());
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_import', array('statistics' => $statistics));
             // everything is imported, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=imported&var=' . ($statistics['imported'] . '/' . $statistics['total']) . $this->filterQuery);
         }
     }
 }
Example #4
0
 /**
  * Imports the locale XML file
  *
  * @param string $filename           The full path for the XML-file.
  * @param bool   $overwriteConflicts Should we overwrite when there is a conflict?
  */
 protected function importLocale($filename, $overwriteConflicts = false)
 {
     $filename = (string) $filename;
     $overwriteConflicts = (bool) $overwriteConflicts;
     // load the file content and execute it
     $content = trim(file_get_contents($filename));
     // file actually has content
     if (!empty($content)) {
         // load xml
         $xml = @simplexml_load_string($content);
         // import if it's valid xml
         if ($xml !== false) {
             // import locale
             BackendLocaleModel::importXML($xml, $overwriteConflicts, $this->getLanguages(), $this->getInterfaceLanguages(), $this->getDefaultUserID(), gmdate('Y-m-d H:i:s'));
         }
     }
 }