/**
  * Helper function to show a table
  *
  * @param string $caption
  * @param array $data
  * @param boolean $nested
  */
 protected function _showTable($caption, $data, $nested = false)
 {
     $table = \MUtil_Html_TableElement::createArray($data, $caption, $nested);
     $table->class = 'browser table';
     $div = \MUtil_Html::create()->div(array('class' => 'table-container'));
     $div[] = $table;
     $this->html[] = $div;
 }
예제 #2
0
 /**
  * Displays the content
  *
  * @param string $value
  * @return string
  */
 public function formatTable($value)
 {
     if (null === $value || is_scalar($value)) {
         return $value;
     }
     if (is_array($value)) {
         $i = 0;
         $output = new \MUtil_Html_Sequence();
         $output->setGlue($this->_separator);
         foreach ($value as $val) {
             if ($i++ > $this->_maxTable) {
                 $output->append($this->_more);
                 break;
             }
             $output->append($val);
         }
         return $output;
     }
     return \MUtil_Html_TableElement::createArray($value);
 }
 public function patchAction()
 {
     $this->html->h3($this->_('Patch maintenance'));
     $patcher = new \Gems_Util_DatabasePatcher($this->db, 'patches.sql', $this->escort->getDatabasePaths());
     $tableSql = sprintf('SELECT gpa_level AS `%s`, gpa_location AS `%s`, COUNT(*) AS `%s`, COUNT(*) - SUM(gpa_executed) AS `%s`, SUM(gpa_executed) AS `%s`, SUM(gpa_completed) AS `%s`, MAX(gpa_changed) AS `%s` FROM gems__patches GROUP BY gpa_level, gpa_location ORDER BY gpa_level DESC, gpa_location', $this->_('Level'), $this->_('Subtype'), $this->_('Patches'), $this->_('To be executed'), $this->_('Executed'), $this->_('Finished'), $this->_('Changed on'));
     $form = $this->createForm();
     $form->setName('database_patcher');
     $form->addElement($form->createElement('exhibitor', 'app_level', array('label' => $this->_('Gems build'))));
     $form->addElement($form->createElement('exhibitor', 'db_level', array('label' => $this->_('Database build'))));
     $level = $form->createElement('text', 'level', array('label' => $this->_('Execute level')));
     $level->addValidator(new \Zend_Validate_Digits());
     $form->addElement($level);
     $form->addElement($form->createElement('checkbox', 'completed', array('label' => $this->_('Ignore finished'))));
     $form->addElement($form->createElement('checkbox', 'executed', array('label' => $this->_('Ignore executed'))));
     $form->addElement($form->createElement('submit', 'show_button', array('label' => $this->_('Show patches'), 'class' => 'button')));
     // $execute = new \Zend_Form_Element_Submit('save_button',   array('label' => $this->_('Execute'), 'class' => 'button'));
     // $form->addElement($execute);
     if ($this->request->isPost()) {
         $data = $this->request->getPost();
         if ($form->isValid($data)) {
             $batch = $this->loader->getTaskRunnerBatch(__CLASS__ . $data['level']);
             $batch->setFormId($form->getId());
             if (!$batch->isLoaded()) {
                 $patcher->loadPatchBatch($data['level'], $data['completed'], $data['executed'], $batch);
             }
             $this->_helper->batchRunner($batch, sprintf($this->_('Executing patch level %d'), $data['level']), $this->accesslog);
             $data['db_level'] = $data['level'];
             $form->getElement('db_level')->setValue($data['db_level']);
             $tableSql = sprintf('SELECT gpa_id_patch AS `%s`, gpa_level AS `%s`, gpa_location AS `%s`, gpa_name AS `%s`, gpa_sql AS `%s`, gpa_executed AS `%s`, gpa_completed AS `%s`, gpa_result AS `%s`, gpa_changed AS `%s` FROM gems__patches WHERE gpa_level = ? ORDER BY gpa_level, gpa_changed DESC, gpa_location, gpa_name, gpa_order', $this->_('Patch'), $this->_('Level'), $this->_('Subtype'), $this->_('Name'), $this->_('Query'), $this->_('Executed'), $this->_('Finished'), $this->_('Result'), $this->_('Changed on'));
             $tableSql = $this->db->quoteInto($tableSql, $data['level']);
             // Hide the form: it is needed for the batch post, but we do not want it visible
             $form->setAttrib('style', 'display: none;');
             if ($this->getMessenger()->getCurrentMessages()) {
                 $this->accesslog->logChange($this->_request);
             }
         }
     } else {
         $changed = $patcher->uploadPatches($this->loader->getVersions()->getBuild());
         if ($changed == -1) {
             $this->addMessage($this->_('Create the patch table!'));
         } elseif ($changed) {
             $this->addMessage(sprintf($this->_('%d new or changed patch(es).'), $changed));
             $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('sess_' . session_id()));
         }
         $data['app_level'] = $this->loader->getVersions()->getBuild();
         $data['db_level'] = $this->db->fetchOne('SELECT gpl_level FROM gems__patch_levels ORDER BY gpl_level DESC');
         $data['level'] = min($data['db_level'] + 1, $data['app_level']);
         $data['completed'] = 1;
         $data['executed'] = 0;
         $form->populate($data);
     }
     if (!\MUtil_Bootstrap::enabled()) {
         $table = new \MUtil_Html_TableElement(array('class' => 'formTable'));
         $table->setAsFormLayout($form, true, true);
         $table['tbody'][0][0]->class = 'label';
         // Is only one row with formLayout, so all in output fields get class.
         if ($links = $this->createMenuLinks(1)) {
             $table->tf();
             // Add empty cell, no label
             $linksCell = $table->tf($links);
         }
     }
     $this->html[] = $form;
     if ($data = $this->db->fetchAll($tableSql)) {
         $table = \MUtil_Html_TableElement::createArray($data, $this->_('Patch overview'), true);
         $table->class = 'browser table table-striped table-bordered table-hover table-condensed';
         $this->html[] = $table;
     }
 }