예제 #1
0
 /**
  * Execute the command.
  *
  * @return  void
  *
  * @since   1.0
  * @throws  AbortException
  * @throws  \RuntimeException
  * @throws  \UnexpectedValueException
  */
 public function execute()
 {
     $this->getApplication()->outputTitle(g11n3t('Installer'));
     $this->db = $this->getContainer()->get('db');
     try {
         // Check if the database "exists"
         $tables = $this->db->getTableList();
         if (!$this->getApplication()->input->get('reinstall')) {
             $this->out()->out('<fg=black;bg=yellow>' . g11n3t('WARNING: A database has been found !!') . '</fg=black;bg=yellow>')->out()->out(g11n3t('Do you want to reinstall ?'))->out()->out('1) ' . g11n3t('Yes'))->out('2) ' . g11n3t('No'))->out()->out('<question>' . g11n3t('Select:') . '</question>', false);
             $in = trim($this->getApplication()->in());
             if (1 != (int) $in) {
                 throw new AbortException();
             }
         }
         $this->cleanDatabase($tables)->outOK();
     } catch (\RuntimeException $e) {
         // Check if the message is "Could not connect to database."  Odds are, this means the DB isn't there or the server is down.
         if (strpos($e->getMessage(), 'Could not connect to database.') !== false) {
             // ? really..
             $this->out(g11n3t('No database found.'))->out(g11n3t('Creating the database...'), false);
             $this->db->setQuery('CREATE DATABASE ' . $this->db->quoteName($this->getApplication()->get('database.name')))->execute();
             $this->db->select($this->getApplication()->get('database.name'));
             $this->outOK();
         } else {
             throw $e;
         }
     }
     // Perform the installation
     $this->processSql()->out()->out('<ok>' . g11n3t('Installation has terminated successfully.') . '</ok>');
 }
예제 #2
0
 /**
  * Execute the command.
  *
  * @return  void
  *
  * @since   1.0
  * @throws  AbortException
  * @throws  \RuntimeException
  * @throws  \UnexpectedValueException
  */
 public function execute()
 {
     try {
         // Check if the database "exists"
         $tables = $this->db->getTableList();
         if (!$this->app->input->get('reinstall')) {
             $this->app->out('<fg=black;bg=yellow>WARNING: A database has been found !!</fg=black;bg=yellow>')->out('Do you want to reinstall ? [y]es / [[n]]o :', false);
             $in = trim($this->app->in());
             if (!in_array($in, ['yes', 'y'])) {
                 throw new AbortException();
             }
         }
         $this->cleanDatabase($tables);
         $this->app->out("\nFinished!");
     } catch (\RuntimeException $e) {
         // Check if the message is "Could not connect to database."  Odds are, this means the DB isn't there or the server is down.
         if (strpos($e->getMessage(), 'Could not connect to database.') !== false) {
             // ? really..
             $this->app->out('No database found.')->out('Creating the database...', false);
             $this->db->setQuery('CREATE DATABASE ' . $this->db->quoteName($this->config->get('database.name')))->execute();
             $this->db->select($this->config->get('database.name'));
             $this->app->out("\nFinished!");
         } else {
             throw $e;
         }
     }
     // Perform the installation
     $this->processSql();
     $this->app->out('Installer has terminated successfully.');
 }
예제 #3
0
 /**
  * Process labels for adding into the issues table
  *
  * @param   integer  $issueId  Issue ID to process
  *
  * @return  array
  *
  * @since   1.0
  */
 protected function processLabels($issueId)
 {
     try {
         $githubLabels = $this->github->issues->get($this->project->gh_user, $this->project->gh_project, $issueId)->labels;
     } catch (\DomainException $exception) {
         $this->logger->error(sprintf('Error parsing the labels for GitHub issue %s/%s #%d - %s', $this->project->gh_user, $this->project->gh_project, $issueId, $exception->getMessage()));
         return '';
     }
     $appLabelIds = array();
     // Make sure the label is present in the database by pulling the ID, add it if it isn't
     $query = $this->db->getQuery(true);
     foreach ($githubLabels as $label) {
         $query->clear()->select($this->db->quoteName('label_id'))->from($this->db->quoteName('#__tracker_labels'))->where($this->db->quoteName('project_id') . ' = ' . (int) $this->project->project_id)->where($this->db->quoteName('name') . ' = ' . $this->db->quote($label->name));
         $this->db->setQuery($query);
         $id = $this->db->loadResult();
         // If null, add the label
         if ($id === null) {
             $table = new LabelsTable($this->db);
             $data = array();
             $data['project_id'] = $this->project->project_id;
             $data['name'] = $label->name;
             $data['color'] = $label->color;
             try {
                 $table->save($data);
                 $id = $table->label_id;
             } catch (\RuntimeException $exception) {
                 $this->logger->error(sprintf('Error adding label %s for project %s/%s to the database: %s', $label->name, $this->project->gh_user, $this->project->gh_project, $exception->getMessage()));
             }
         }
         // Add the ID to the array
         $appLabelIds[] = $id;
     }
     return $appLabelIds;
 }
예제 #4
0
 /**
  * Parses the unit test results and records them into the database
  *
  * @param   string  $package  Package name
  *
  * @return  void
  *
  * @since   1.0
  * @throws  \UnexpectedValueException
  */
 private function recordResults($package)
 {
     // Initialize variables.
     $report = array();
     // Make sure the files exist.
     if (!file_exists(JPATH_ROOT . '/coverage/logs/clover.' . $package . '.xml')) {
         throw new \UnexpectedValueException('The clover test report for the ' . $this->helper->getPackageDisplayName($package) . ' package is missing.');
     }
     if (!file_exists(JPATH_ROOT . '/coverage/logs/junit.' . $package . '.xml')) {
         throw new \UnexpectedValueException('The junit test report for the ' . $this->helper->getPackageDisplayName($package) . ' package is missing.');
     }
     // Display update to console
     $this->app->out('Parsing test results for the ' . $this->helper->getPackageDisplayName($package) . ' package and recording to the database.');
     // Load the Clover XML file.
     $xml = simplexml_load_file(JPATH_ROOT . '/coverage/logs/clover.' . $package . '.xml');
     // Get the project metrics element.
     $metrics = $xml->project[0]->metrics[0];
     // Add the data to the report
     $report['total_lines'] = (int) $metrics['statements'];
     $report['lines_covered'] = (int) $metrics['coveredstatements'];
     // Load the JUnit XML file
     $xml = simplexml_load_file(JPATH_ROOT . '/coverage/logs/junit.' . $package . '.xml');
     // Get the project testsuite element.
     $metrics = $xml->testsuite[0];
     // Add the data to the report
     $report['assertions'] = (int) $metrics['assertions'];
     $report['tests'] = (int) $metrics['tests'];
     $report['failures'] = (int) $metrics['failures'];
     $report['errors'] = (int) $metrics['errors'];
     // Insert the report data into the database
     $this->db->setQuery($this->db->getQuery(true)->insert($this->db->quoteName('#__test_results'))->columns(array($this->db->quoteName('package_id'), $this->db->quoteName('tests'), $this->db->quoteName('assertions'), $this->db->quoteName('errors'), $this->db->quoteName('failures'), $this->db->quoteName('total_lines'), $this->db->quoteName('lines_covered')))->values((int) $this->packageId . ', ' . $this->db->quote($report['tests']) . ', ' . $this->db->quote($report['assertions']) . ', ' . $this->db->quote($report['errors']) . ', ' . $this->db->quote($report['failures']) . ', ' . $this->db->quote($report['total_lines']) . ', ' . $this->db->quote($report['lines_covered'])))->execute();
 }
예제 #5
0
 /**
  * gc
  *
  * @param string $past
  *
  * @return  bool
  */
 public function gc($past)
 {
     $query = $this->db->getQuery(true);
     $query->delete($this->db->quoteName($this->options['table']))->where($this->db->quoteName($this->options['time_col']) . ' < ' . $this->db->quote((int) $past));
     // Remove expired sessions from the database.
     $this->db->setQuery($query);
     return (bool) $this->db->execute();
 }
예제 #6
0
 /**
  * Garbage collect stale sessions from the SessionHandler backend.
  *
  * @param   integer  $lifetime  The maximum age of a session.
  *
  * @return  boolean  True on success, false otherwise.
  *
  * @since   1.0
  */
 public function gc($lifetime = 1440)
 {
     // Determine the timestamp threshold with which to purge old sessions.
     $past = time() - $lifetime;
     try {
         $query = $this->db->getQuery(true);
         $query->delete($this->db->quoteName('#__session'))->where($this->db->quoteName('time') . ' < ' . $this->db->quote((int) $past));
         // Remove expired sessions from the database.
         $this->db->setQuery($query);
         return (bool) $this->db->execute();
     } catch (\Exception $e) {
         return false;
     }
 }
예제 #7
0
 /**
  * Tests the Joomla\Database\DatabaseDriver::quoteName method.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testQuoteName()
 {
     $this->assertThat($this->instance->quoteName('test'), $this->equalTo('[test]'), 'Tests the left-right quotes on a string.');
     $this->assertThat($this->instance->quoteName('a.test'), $this->equalTo('[a].[test]'), 'Tests the left-right quotes on a dotted string.');
     $this->assertThat($this->instance->quoteName(array('a', 'test')), $this->equalTo(array('[a]', '[test]')), 'Tests the left-right quotes on an array.');
     $this->assertThat($this->instance->quoteName(array('a.b', 'test.quote')), $this->equalTo(array('[a].[b]', '[test].[quote]')), 'Tests the left-right quotes on an array.');
     $this->assertThat($this->instance->quoteName(array('a.b', 'test.quote'), array(null, 'alias')), $this->equalTo(array('[a].[b]', '[test].[quote] AS [alias]')), 'Tests the left-right quotes on an array.');
     $this->assertThat($this->instance->quoteName(array('a.b', 'test.quote'), array('alias1', 'alias2')), $this->equalTo(array('[a].[b] AS [alias1]', '[test].[quote] AS [alias2]')), 'Tests the left-right quotes on an array.');
     $this->assertThat($this->instance->quoteName((object) array('a', 'test')), $this->equalTo(array('[a]', '[test]')), 'Tests the left-right quotes on an object.');
     // 		TestHelper::setValue($this->db, 'nameQuote', '/');
     $refl = new \ReflectionClass($this->instance);
     $property = $refl->getProperty('nameQuote');
     $property->setAccessible(true);
     $property->setValue($this->instance, '/');
     $this->assertThat($this->instance->quoteName('test'), $this->equalTo('/test/'), 'Tests the uni-quotes on a string.');
 }
예제 #8
0
 /**
  * Method to append the primary keys for this table to a query.
  *
  * @param DatabaseQuery $query A query object to append.
  * @param mixed         $pk    Optional primary key parameter.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  */
 public function appendPrimaryKeys($query, $pk = null)
 {
     if (is_null($pk)) {
         foreach ($this->tableKeys as $k) {
             $query->where($this->db->quoteName($k) . ' = ' . $this->db->quote($this->{$k}));
         }
     } else {
         if (is_string($pk)) {
             $pk = array($this->tableKeys[0] => $pk);
         }
         $pk = (object) $pk;
         foreach ($this->tableKeys as $k) {
             $query->where($this->db->quoteName($k) . ' = ' . $this->db->quote($pk->{$k}));
         }
     }
     return $this;
 }
예제 #9
0
 /**
  * Execute the command
  *
  * @return  void
  *
  * @since   1.0
  */
 public function execute()
 {
     // Display status
     $this->app->out('Parsing the Composer data.');
     // Get the Composer data
     $helper = new Helper();
     $packages = $helper->parseComposer();
     // Insert the records into the database now
     foreach ($packages as $name => $package) {
         // Check to see if the package is already in the database
         $packageID = $this->db->setQuery($this->db->getQuery(true)->select($this->db->quoteName('id'))->from($this->db->quoteName('#__packages'))->where($this->db->quoteName('package') . ' = ' . $this->db->quote($name))->where($this->db->quoteName('version') . ' = ' . $this->db->quote($package['version'])))->loadResult();
         // If not present, insert it
         if (!$packageID) {
             $this->db->setQuery($this->db->getQuery(true)->insert($this->db->quoteName('#__packages'))->columns(array($this->db->quoteName('package'), $this->db->quoteName('version')))->values($this->db->quote($name) . ', ' . $this->db->quote($package['version'])))->execute();
         }
     }
     // Display status
     $this->app->out('Finished parsing Composer data.');
 }
예제 #10
0
 /**
  * getFilterFields
  *
  * @param int $prefixFirst
  *
  * @return  array
  */
 public function getSelectFields($prefixFirst = self::COLS_WITH_FIRST)
 {
     $fields = array();
     $i = 0;
     foreach ($this->tables as $alias => $table) {
         $columns = DatabaseFactory::getCommand()->getColumns($table['name']);
         foreach ($columns as $column => $var) {
             if ($i === 0) {
                 if ($prefixFirst & self::COLS_WITH_FIRST) {
                     $fields[] = $this->db->quoteName("{$alias}.{$column}", $column);
                 }
                 if ($prefixFirst & self::COLS_PREFIX_WITH_FIRST) {
                     $fields[] = $this->db->quoteName("{$alias}.{$column}", "{$alias}_{$column}");
                 }
             } else {
                 $fields[] = $this->db->quoteName("{$alias}.{$column}", "{$alias}_{$column}");
             }
         }
         $i++;
     }
     return $fields;
 }
예제 #11
0
 /**
  * Get the SQL syntax to drop a column.
  *
  * @param   string  $table  The table name.
  * @param   string  $name   The name of the field to drop.
  *
  * @return  string
  *
  * @since   1.0
  */
 protected function getDropColumnSql($table, $name)
 {
     $sql = 'ALTER TABLE ' . $this->db->quoteName($table) . ' DROP COLUMN ' . $this->db->quoteName($name);
     return $sql;
 }