1
0
mirror of https://gitnet.fr/deblan/gist.git synced 2021-08-14 08:30:49 +02:00

Adding of field that contains the number of commits

This commit is contained in:
Simon Vieille 2016-12-23 11:17:56 +01:00
parent df3035f2f1
commit 0e02add6e6
6 changed files with 92 additions and 19 deletions

View File

@ -5,6 +5,7 @@ use Gist\Command\CreateCommand;
use Gist\Command\UpdateCommand;
use Gist\Command\StatsCommand;
use Gist\Command\UserCreateCommand;
use Gist\Command\Migration\UpgradeTo1p4p1Command;
$app = require __DIR__.'/bootstrap.php';
@ -12,5 +13,6 @@ $app['console']->add(new CreateCommand());
$app['console']->add(new UpdateCommand());
$app['console']->add(new StatsCommand());
$app['console']->add(new UserCreateCommand());
$app['console']->add(new UpgradeTo1p4p1Command());
$app['console']->run();

View File

@ -0,0 +1,44 @@
<?php
namespace Gist\Command\Migration;
use Knp\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Gist\Model\GistQuery;
/**
* class UpgradeTo1p4p1Command.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class UpgradeTo1p4p1Command extends Command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('migrate:to:v1.4.1')
->setDescription('Migrates database entries to >= v1.4.1')
->setHelp('The <info>%command.name%</info> migrates database entries to >= v1.4.1');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$app = $this->getSilexApplication();
$gists = GistQuery::create()
->filterByCommits(0)
->find();
foreach ($gists as $gist) {
$commits = $app['gist']->getNumberOfCommits($gist);
$gist->setCommits($commits);
$gist->save();
}
}
}

View File

@ -12,8 +12,8 @@ use GitWrapper\GitException;
/**
* class StatsCommand;
*
* @author Simon Vieille <simon@deblan.fr>
*
* @author Simon Vieille <simon@deblan.fr>
*/
class StatsCommand extends Command
{
@ -30,7 +30,7 @@ Show stats about GIST
EOF
);
}
/**
* {@inheritdoc}
*/
@ -52,18 +52,13 @@ EOF
$withEncryption[$gist->getType()] = 0;
$commits[$gist->getType()] = 0;
}
if ($gist->getCipher()) {
$withEncryption[$gist->getType()]++;
}
$languages[$gist->getType()]++;
try {
$count = count($gistService->getHistory($gist));
$commits[$gist->getType()] += $count;
} catch(GitException $e) {
}
$commits[$gist->getType()] += $gist->getCommits();
}
$output->writeln(['<comment>Gists statistics</comment>', '']);
@ -73,9 +68,9 @@ EOF
->setHeaders(array('Without encryption', 'With encryption', 'Commits', 'Total'))
->setRows(array(
array(
$total - $v = array_sum($withEncryption),
$v,
array_sum($commits),
$total - $v = array_sum($withEncryption),
$v,
array_sum($commits),
$total
),
))
@ -90,9 +85,9 @@ EOF
$table->setHeaders(array(
'Type',
'Without encryption',
'With encryption',
'Commits',
'Without encryption',
'With encryption',
'Commits',
'Total',
));

View File

@ -76,4 +76,14 @@ class Gist extends BaseGist
return str_replace(array_keys($data), array_values($data), $this->getType());
}
/*
* Increments the number of commits.
*/
public function commit()
{
$this->setCommits($this->getCommits() + 1);
return $this;
}
}

View File

@ -7,7 +7,8 @@
<column name="type" type="VARCHAR" size="30" required="true" />
<column name="file" type="VARCHAR" size="30" required="true" />
<column name="user_id" type="INTEGER" required="false" />
<column name="commits" type="INTEGER" required="true" defaultValue="0" />
<foreign-key foreignTable="user" onDelete="setnull" onUpdate="cascade">
<reference local="user_id" foreign="id"/>
</foreign-key>

View File

@ -149,7 +149,7 @@ class Gist
$gist->setUser($user);
}
$gist->save();
$gist->commit()->save();
return $gist;
}
@ -170,9 +170,30 @@ class Gist
->add($gist->getFile())
->commit('Update');
$gist->commit()->save();
return $gist;
}
/*
* Returns the number of commits.
*
* @param GistModel $gist
*
* @return int
*/
public function getNumberOfCommits(GistModel $gist)
{
$command = GitCommand::getInstance('log', '--oneline', '--', $gist->getFile());
$command->setDirectory($this->gistPath);
$command->bypass(false);
$content = trim($this->gitWrapper->run($command));
$content = str_replace("\r\n", "\n", $content);
return count(explode("\n", $content));
}
/**
* Highlight the content.
*