Ejemplo n.º 1
0
 /**
  * Create a job file
  *
  * @return bool True on success
  *
  * @throws Exception If something happens when the zip file is being created.
  */
 public function generateJobFile()
 {
     $filename = $this->getFileName();
     $jobData = array('jobId' => $this->getId(), 'job_create_time' => $this->getCreatedTime(true), 'file_name' => $filename, 'translation_method' => NenoHelper::convertTranslationMethodIdToName($this->getTranslationMethod()->id), 'from' => $this->getFromLanguage(), 'to' => $this->getToLanguage(), 'comment' => NenoSettings::get('external_translators_notes'), 'strings' => $this->getTranslations());
     $config = JFactory::getConfig();
     $tmpPath = $config->get('tmp_path');
     $fileData = array('name' => $filename . '.json', 'data' => json_encode($jobData));
     /* @var $zipArchiveAdapter JArchiveZip */
     $zipArchiveAdapter = JArchive::getAdapter('zip');
     $result = $zipArchiveAdapter->create($tmpPath . '/' . $filename . '.json.zip', array($fileData));
     $this->fileName = $filename;
     // If something happens in the process of creating the job file, let's throw an exception
     if (!$result) {
         throw new Exception('Error creating job file');
     }
     $this->persist();
     return $result;
 }