示例#1
0
 /**
  * Process install files.
  *
  * @throws EcrExceptionZiper
  *
  * @return EcrProjectZiper
  */
 private function processInstall()
 {
     $installFiles = EcrProjectHelper::findInstallFiles($this->project);
     if (0 == count($installFiles['php'])) {
         return $this;
     }
     $srcDir = $this->temp_dir . DS . 'admin';
     $destDir = $this->temp_dir . DS . 'install';
     //-- Create 'install' folder in temp dir
     JFolder::create($destDir);
     //-- Copy install files from 'admin' to 'temp'
     foreach ($installFiles['php'] as $file) {
         $srcPath = $srcDir;
         $srcPath .= $file->folder ? DS . $file->folder : '';
         $srcPath .= DS . $file->name;
         $destPath = $destDir;
         if ($file->folder == 'install') {
             $folder = '';
         } else {
             $folder = str_replace('install' . DS, '', $file->folder);
         }
         if ($folder) {
             $destPath .= DS . $folder;
             //-- Create the folder
             JFolder::create($destPath);
         }
         if (JFile::copy($srcPath, $destPath . DS . $file->name)) {
             $this->logger->log('COPY INSTALL FILE<br />SRC: ' . $srcPath . '<br />DST: ' . $destPath . DS . $file->name);
         } else {
             $this->logger->log('COPY INSTALL FILE<br />SRC: ' . $srcPath . '<br />DST: ' . $destPath . DS . $file->name, 'ERROR copy file');
             continue;
         }
         if (0 != strpos($file->name, 'install')) {
             continue;
         }
         if ($this->buildopts['createMD5']) {
             $format = 'po' == $this->project->langFormat ? '.po' : '';
             $compressed = $this->buildopts['createMD5Compressed'] ? '_compressed' : '';
             $fileContents = JFile::read(ECRPATH_EXTENSIONTEMPLATES . DS . 'std' . DS . 'md5check' . $compressed . $format . '.php');
             $fileContents = str_replace('<?php', '', $fileContents);
             $this->project->addSubstitute('##ECR_MD5CHECK_FNC##', $fileContents);
             $fileContents = JFile::read(ECRPATH_EXTENSIONTEMPLATES . DS . 'std' . DS . 'md5check_call' . $format . '.php');
             $fileContents = str_replace('<?php', '', $fileContents);
             $this->project->addSubstitute('##ECR_MD5CHECK##', $fileContents);
             $this->project->addSubstitute('ECR_COM_COM_NAME', $this->project->comName);
             $fileContents = JFile::read($destPath . DS . $file->name);
             $fileContents = $this->project->substitute($fileContents);
         } else {
             $this->project->addSubstitute('##ECR_MD5CHECK_FNC##', '');
             $this->project->addSubstitute('##ECR_MD5CHECK##', '');
             $fileContents = JFile::read($destPath . DS . $file->name);
             $fileContents = $this->project->substitute($fileContents);
         }
         if (JFile::write($destPath . DS . $file->name, $fileContents)) {
             $this->logger->logFileWrite('', 'install/install.php', $fileContents);
         } else {
             $this->logger->log('Failed to add MD5 install check routine to install.php', 'error');
         }
     }
     //-- Delete install files from 'admin'
     foreach ($installFiles['php'] as $file) {
         $srcPath = $srcDir;
         $srcPath .= $file->folder ? DS . $file->folder : '';
         $srcPath .= DS . $file->name;
         if (false == JFile::delete($srcPath)) {
             throw new EcrExceptionZiper(__METHOD__ . ' - Delete install file failed: ' . $srcPath);
         }
         $this->logger->log('INSTALL FILE DELETED<br />SRC: ' . $srcPath);
     }
     return $this;
 }
示例#2
0
 /**
  * Inserts the part into the project.
  *
  * @param EcrProjectBase $project The project.
  * @param array $options Insert options.
  * @param EcrLogger $logger The EcrLogger.
  *
  * @return boolean
  */
 public function insert(EcrProjectBase $project, $options, EcrLogger $logger)
 {
     $input = JFactory::getApplication()->input;
     $element_name = $input->get('element_name');
     $table_name = $input->get('table_name');
     $req_table_fields = $input->get('table_fields', array(), 'array');
     $req_table_fields_edits = $input->get('table_fields_edits', array(), 'array');
     $req_table_fields_types = $input->get('table_fields_types', array(), 'array');
     if (!$table_name) {
         JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error');
         return false;
     }
     $db = JFactory::getDBO();
     $prefix = $db->getPrefix();
     $fields = $db->getTableFields($prefix . $table_name);
     $tableFields = array();
     $table_vars = '';
     if (count($fields)) {
         $tableFields = $fields[$prefix . $table_name];
         foreach ($tableFields as $key => $value) {
             if (!in_array($key, $req_table_fields)) {
                 continue;
             }
             $table_vars .= EcrTableHelper::formatTableVar($key, $value);
         }
         //foreach
     }
     /*
      * Add substitutes
      */
     $project->addSubstitute('ECR_ELEMENT_NAME', $element_name);
     $project->addSubstitute('_ECR_LOWER_ELEMENT_NAME_', strtolower($element_name));
     $project->addSubstitute('_ECR_TABLE_NAME_', $table_name);
     $project->addSubstitute('##ECR_TABLE_VARS##', $table_vars);
     /*
      * Read part options files
      */
     $files = JFolder::files($options->pathSource . DS . 'options', '.', true, true);
     foreach ($files as $file) {
         $fileContents = JFile::read($file);
         if (strpos($fileContents, '<?php') === 0) {
             $fileContents = substr($fileContents, 6);
         }
         $project->substitute($fileContents);
         $project->addSubstitute('##' . strtoupper(JFile::stripExt(JFile::getName($file))) . '##', $fileContents);
     }
     //foreach
     /*
      * Add manual substitutes
      */
     $substitutes['##ECR_VIEW1_TMPL1_THS##'] = '?>';
     $substitutes['##ECR_VIEW1_TMPL1_TDS##'] = '?>';
     $substitutes['##ECR_VIEW2_TMPL1_OPTION2##'] = '?>';
     $i = 0;
     foreach ($tableFields as $key => $value) {
         if (!in_array($key, $req_table_fields)) {
             continue;
         }
         $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= '    <th>' . NL;
         $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= "        <?php echo JHTML::_('grid.sort', '" . $key . "', '" . $key . "', \$this->lists['order_Dir'], \$this->lists['order']);?>" . NL;
         $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= '    </th>' . NL;
         $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= '    <td>' . NL;
         $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= '        <?php echo $row->' . $key . '; ?>' . NL;
         $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= '    </td>' . NL;
         if (in_array($key, $req_table_fields_edits)) {
             $s = $project->getSubstitute('##ECR_VIEW2_TMPL1_OPTION2VAL##');
             $s = str_replace('_ECR_FIELDVALUE_1_', $key, $s);
             $s = str_replace('_ECR_FIELDVALUE_2_', $req_table_fields_types[$key], $s);
             $substitutes['##ECR_VIEW2_TMPL1_OPTION2##'] .= $s;
         }
         $i++;
     }
     //foreach
     $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= '    <?php $coloumnCount += ' . $i . '; ?>' . NL;
     $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= '    <?php ' . NL;
     $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= '    <?php ' . NL;
     $substitutes['##ECR_VIEW2_TMPL1_OPTION2##'] .= '    <?php ' . NL;
     foreach ($substitutes as $key => $value) {
         $project->addSubstitute($key, $value);
     }
     //foreach
     /*
      * Remove options
      */
     if (!in_array('ordering', $req_table_fields)) {
         $project->addSubstitute('##ECR_CONTROLLER1_OPTION1##', '');
     }
     if (!in_array('published', $req_table_fields)) {
     }
     $project->addSubstitute('ECR_SUBPACKAGE', 'Tables');
     $input->set('element_scope', 'admin');
     if (!$project->insertPart($options, $logger)) {
         return false;
     }
     /*
      * Create menu link
      */
     if ($input->get('create_menu_link', false)) {
         $link = 'option=' . $options->ecr_project . '&view=' . strtolower($element_name) . $project->listPostfix . '&controller=' . strtolower($element_name) . $project->listPostfix;
         if (!$project->addSubmenuEntry($element_name, $link)) {
             JFactory::getApplication()->enqueueMessage(jgettext('Unable to create menu link'), 'error');
             return false;
         }
     }
     return true;
 }