Пример #1
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();
 }
Пример #2
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;
 }
Пример #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();
 }
Пример #4
0
 /**
  * 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;
 }
Пример #5
0
 /**
  * Tests the \Joomla\Database\DatabaseQuery::__clone method properly clones an object.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function test__clone_object()
 {
     $baseElement = $this->dbo->getQuery(true);
     $baseElement->testObject = new \stdClass();
     $cloneElement = clone $baseElement;
     $this->assertThat(TestHelper::getValue($baseElement, 'db'), $this->identicalTo(TestHelper::getValue($cloneElement, 'db')), 'The cloned $db variable should be identical after cloning.');
     $this->assertFalse($baseElement === $cloneElement);
     $this->assertFalse($baseElement->testObject === $cloneElement->testObject);
 }
Пример #6
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.');
 }
Пример #7
0
 /**
  * Batch update some data.
  *
  * @param string $table      Table name.
  * @param string $data       Data you want to update.
  * @param mixed  $conditions Where conditions, you can use array or Compare object.
  *                           Example:
  *                           - `array('id' => 5)` => id = 5
  *                           - `new GteCompare('id', 20)` => 'id >= 20'
  *                           - `new Compare('id', '%Flower%', 'LIKE')` => 'id LIKE "%Flower%"'
  *
  * @return  boolean True if update success.
  */
 public function updateBatch($table, $data, $conditions = array())
 {
     $query = $this->db->getQuery(true);
     // Build conditions
     $query = QueryHelper::buildWheres($query, $conditions);
     // Build update values.
     $fields = array_keys($this->getColumns($table));
     $hasField = false;
     foreach ((array) $data as $field => $value) {
         if (!in_array($field, $fields)) {
             continue;
         }
         $query->set($query->format('%n = %q', $field, $value));
         $hasField = true;
     }
     if (!$hasField) {
         return false;
     }
     $query->update($table);
     return $this->db->setQuery($query)->execute();
 }
Пример #8
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;
     }
 }
Пример #9
0
 /**
  * Do delete action, this method should be override by sub class.
  *
  * @param mixed $conditions Where conditions, you can use array or Compare object.
  *
  * @throws \Exception
  * @return  boolean Will be always true.
  */
 protected function doDelete(array $conditions)
 {
     $query = $this->db->getQuery(true);
     // Conditions.
     QueryHelper::buildWheres($query, $conditions);
     $query->delete($this->table);
     $this->db->transactionStart(true);
     try {
         $result = (bool) $this->db->setQuery($query)->execute();
     } catch (\Exception $e) {
         $this->db->transactionRollback(true);
         throw $e;
     }
     $this->db->transactionCommit(true);
     return $result;
 }
Пример #10
0
 /**
  * Merges the incoming structure definition with the existing structure.
  *
  * @return  void
  *
  * @note    Currently only supports XML format.
  * @since   1.0
  * @throws  \RuntimeException on error.
  */
 public function mergeStructure()
 {
     $tables = $this->db->getTableList();
     if ($this->from instanceof \SimpleXMLElement) {
         $xml = $this->from;
     } else {
         $xml = new \SimpleXMLElement($this->from);
     }
     // Get all the table definitions.
     $xmlTables = $xml->xpath('database/table_structure');
     foreach ($xmlTables as $table) {
         // Convert the magic prefix into the real table name.
         $tableName = $this->getRealTableName((string) $table['name']);
         if (in_array($tableName, $tables)) {
             // The table already exists. Now check if there is any difference.
             if ($queries = $this->getAlterTableql($xml->database->table_structure)) {
                 // Run the queries to upgrade the data structure.
                 foreach ($queries as $query) {
                     $this->db->setQuery((string) $query);
                     try {
                         $this->db->execute();
                     } catch (\RuntimeException $e) {
                         $this->db->log(LogLevel::DEBUG, 'Fail: ' . $this->db->getQuery());
                         throw $e;
                     }
                     $this->db->log(LogLevel::DEBUG, 'Pass: '******'Fail: ' . $this->db->getQuery());
                 throw $e;
             }
             $this->db->log(LogLevel::DEBUG, 'Pass: ' . $this->db->getQuery());
         }
     }
 }
 /**
  * Validate that the primary key has been set.
  *
  * @return  boolean  True if the primary key(s) have been set.
  *
  * @since   1.0
  */
 public function hasPrimaryKey()
 {
     if ($this->autoIncrement) {
         $empty = true;
         foreach ($this->tableKeys as $key) {
             $empty = $empty && !$this->{$key};
         }
     } else {
         $query = $this->db->getQuery(true)->select('COUNT(*)')->from($this->tableName);
         $this->appendPrimaryKeys($query);
         $this->db->setQuery($query);
         $count = $this->db->loadResult();
         if ($count == 1) {
             $empty = false;
         } else {
             $empty = true;
         }
     }
     return !$empty;
 }
Пример #12
0
 /**
  * Select a user by conditions.
  *
  * @param array $where    an associative array of WHERE contitions
  * @param array $where    an associative array of SELECT contitions
  * @return object object of founded info about user
  */
 public function getEmails()
 {
     if ($this->emails) {
         return $this->emails;
     }
     $query = $this->database->getQuery(true);
     $query->select('email')->from('#__users_email_cf');
     $query->where('member_id=' . (int) $this->get('id'));
     $this->emails = $this->database->setQuery($query)->loadObjectList();
     return $this->emails;
 }