Skip to content

Commit

Permalink
Update versions for change to semantic versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
gapple committed Aug 16, 2014
1 parent 7e7f0ac commit 0f0828e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 36 deletions.
15 changes: 7 additions & 8 deletions src/DrupalReleaseDate/Controllers/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function samples(Application $app, Request $request)
$lastQuery = $app['db']->createQueryBuilder()
->select('s.when')
->from('samples', 's')
->where('version = 8')
->where('version = "8.0"')
->orderBy($app['db']->quoteIdentifier('when'), 'DESC')
->setMaxResults(1);
if ($from) {
Expand Down Expand Up @@ -95,7 +95,7 @@ public function samples(Application $app, Request $request)
'sv.value'
)
->from('sample_values', 'sv')
->where('version = 8')
->where('version = "8.0"')
->orderBy($app['db']->quoteIdentifier('when'), 'ASC');
if ($from) {
$sampleValuesQuery
Expand Down Expand Up @@ -144,7 +144,7 @@ public function historical(Application $app, Request $request)
$currentSample = $app['db']->createQueryBuilder()
->select('s.when')
->from('samples', 's')
->where('version = 8')
->where('version = "8.0"')
->orderBy($app['db']->quoteIdentifier('when'), 'DESC')
->setMaxResults(1)
->execute()
Expand Down Expand Up @@ -184,7 +184,7 @@ public function historical(Application $app, Request $request)
$pastSampleQuery = $app['db']->createQueryBuilder()
->select('s.version', 's.when')
->from('samples', 's')
->where('version = 8')
->where('version = "8.0"')
->orderBy($app['db']->quoteIdentifier('when'), 'DESC')
->setMaxResults(1);
if ($periodInterval) {
Expand Down Expand Up @@ -262,7 +262,7 @@ public function estimates(Application $app, Request $request)
$lastQuery = $app['db']->createQueryBuilder()
->select('e.when', 'e.estimate')
->from('estimates', 'e')
->where('version = 8')
->where('version = "8.0"')
->andWhere('completed IS NOT NULL')
->orderBy($app['db']->quoteIdentifier('when'), 'DESC')
->setMaxResults(1);
Expand Down Expand Up @@ -310,7 +310,7 @@ public function estimates(Application $app, Request $request)
$queryBuilder = $app['db']->createQueryBuilder()
->select('e.when', 'e.estimate')
->from('estimates', 'e')
->where('version = 8')
->where('version = "8.0"')
->andWhere('completed IS NOT NULL')
->orderBy($app['db']->quoteIdentifier('when'), 'ASC');
if ($from) {
Expand Down Expand Up @@ -378,7 +378,7 @@ public function distribution(Application $app, Request $request)
$query = $app['db']->createQueryBuilder()
->select('e.when', 'e.estimate', 'e.data')
->from('estimates', 'e')
->where('version = 8')
->where('version = "8.0"')
->andWhere('completed IS NOT NULL')
->orderBy($app['db']->quoteIdentifier('when'), 'DESC')
->setMaxResults(1);
Expand All @@ -388,7 +388,6 @@ public function distribution(Application $app, Request $request)
->andWhere('e.when = :when')
->setParameter('when', $app['db']->convertToDatabaseValue($date, 'datetime'), \PDO::PARAM_STR);
}

$results = $query->execute();

if ($row = $results->fetch(\PDO::FETCH_ASSOC)) {
Expand Down
47 changes: 47 additions & 0 deletions src/DrupalReleaseDate/Installation.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,51 @@ protected function update_4()
->execute();
}
}

/**
* Update version fields to store semantic version string.
*/
protected function update_5()
{
// Update version field type.
$schema = $this->app['db']->getSchemaManager()->createSchema();
$schema = clone $schema;

$estimates = $schema->getTable('estimates');
$estimates->changeColumn('version', array(
'type' => \Doctrine\DBAL\Types\Type::getType('string'),
'length' => 32,
));

$samples = $schema->getTable('samples');
$samples->changeColumn('version', array(
'type' => \Doctrine\DBAL\Types\Type::getType('string'),
'length' => 32,
));

$sampleValues = $schema->getTable('sample_values');
$sampleValues->changeColumn('version', array(
'type' => \Doctrine\DBAL\Types\Type::getType('string'),
'length' => 32,
));

$synchronizer = new \Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer($this->app['db']);
$synchronizer->updateSchema($schema);

// Convert existing data.
$this->app['db']->createQueryBuilder()
->update('estimates', 'e')
->set('e.version', 'CONCAT(e.version, ".0")')
->execute();

$this->app['db']->createQueryBuilder()
->update('samples', 's')
->set('s.version', 'CONCAT(s.version, ".0")')
->execute();

$this->app['db']->createQueryBuilder()
->update('sample_values', 'sv')
->set('sv.version', 'CONCAT(sv.version, ".0")')
->execute();
}
}
53 changes: 25 additions & 28 deletions src/DrupalReleaseDate/Repository/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function estimate(array $config = array())
->from('samples', 's')
->join('s', 'sample_values', 'sv_bugs', 's.version = sv_bugs.version && s.when = sv_bugs.when && sv_bugs.key="critical_bugs"')
->join('s', 'sample_values', 'sv_tasks', 's.version = sv_tasks.version && s.when = sv_tasks.when && sv_tasks.key="critical_tasks"')
->where('s.version = 8')
->where('s.version = "8.0"')
->having('value IS NOT NULL')
->orderBy($db->quoteIdentifier('when'), 'ASC')
->execute();
Expand All @@ -67,7 +67,7 @@ public function estimate(array $config = array())
$db->quoteIdentifier('estimates'),
array(
$db->quoteIdentifier('when') => $lastResult->when,
$db->quoteIdentifier('version') => 8,
$db->quoteIdentifier('version') => '8.0',
$db->quoteIdentifier('data') => '',
$db->quoteIdentifier('started') => $db->convertToDatabaseValue(new DateTime(), 'datetime'),
)
Expand Down Expand Up @@ -120,7 +120,7 @@ public function estimate(array $config = array())
$update,
array(
$db->quoteIdentifier('when') => $lastResult->when,
$db->quoteIdentifier('version') => 8,
$db->quoteIdentifier('version') => '8.0',
)
);
}
Expand All @@ -136,39 +136,36 @@ public function samples(\Guzzle\Http\ClientInterface $httpClient, array $config)
{
$db = $this->db;

$versions = array(
'8.0' => '8.0.x-dev',
'8.1' => '8.1.x-dev',
'9.0' => '9.x', // 9.x has not been updated to semantic versioning yet
);

$queryDataDefaults = array(
$db->quoteIdentifier('when') => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']),
);

$counter = new \DrupalReleaseDate\DrupalIssueCount($httpClient);

$d8CommonParameters = array(
'version' => array('8.x')
) + $config['common'];
$d8results = $counter->getCounts($d8CommonParameters, $config['sets']);
$queryData = $queryDataDefaults + array(
$db->quoteIdentifier('version') => 8,
);
$db->insert($db->quoteIdentifier('samples'), $queryData);
foreach ($d8results as $resultKey => $resultValue) {
$queryData[$db->quoteIdentifier('key')] = $resultKey;
$queryData[$db->quoteIdentifier('value')] = $resultValue;
$db->insert($db->quoteIdentifier('sample_values'), $queryData);
}
foreach ($versions as $versionId => $versionKey) {
$commonParameters = array(
'version' => array($versionKey)
) + $config['common'];

$countResults = $counter->getCounts($commonParameters, $config['sets']);

$d9CommonParameters = array(
'version' => array('9.x')
) + $config['common'];
$d9results = $counter->getCounts($d9CommonParameters, $config['sets']);
$queryData = $queryDataDefaults + array(
$db->quoteIdentifier('version') => 9,
);
$db->insert($db->quoteIdentifier('samples'), $queryData);
foreach ($d9results as $resultKey => $resultValue) {
$queryData[$db->quoteIdentifier('key')] = $resultKey;
$queryData[$db->quoteIdentifier('value')] = $resultValue;
$db->insert($db->quoteIdentifier('sample_values'), $queryData);
$queryData = $queryDataDefaults + array(
$db->quoteIdentifier('version') => $versionId,
);

$db->insert($db->quoteIdentifier('samples'), $queryData);

foreach ($countResults as $resultKey => $resultValue) {
$queryData[$db->quoteIdentifier('key')] = $resultKey;
$queryData[$db->quoteIdentifier('value')] = $resultValue;
$db->insert($db->quoteIdentifier('sample_values'), $queryData);
}
}
}
}

0 comments on commit 0f0828e

Please sign in to comment.