/**
  * 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;
 }
 /**
  * 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();
 }
Beispiel #3
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();
 }
 /**
  * Retrieve the hashed password for the specified user.
  *
  * @param   string  $username  Username to lookup.
  *
  * @return  string|boolean  Hashed password on success or boolean false on failure.
  *
  * @since   1.1.0
  */
 protected function getHashedPassword($username)
 {
     $password = $this->db->setQuery($this->db->getQuery(true)->select($this->dbOptions['password_column'])->from($this->dbOptions['database_table'])->where($this->dbOptions['username_column'] . ' = ' . $this->db->quote($username)))->loadResult();
     if (!$password) {
         return false;
     }
     return $password;
 }
 /**
  * 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.');
 }
 /**
  * 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;
     }
 }
Beispiel #7
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;
 }
Beispiel #8
0
 /**
  * Tests the Joomla\Database\DatabaseDriver::quote method.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testQuoteFloat()
 {
     $this->assertThat($this->instance->quote(3.14), $this->equalTo("'-3.14-'"), 'Tests handling of float with escaping (default).');
 }