Skip to content

Commit

Permalink
code review closes academic#608
Browse files Browse the repository at this point in the history
  • Loading branch information
behram committed May 22, 2015
1 parent c8f7979 commit 217514a
Show file tree
Hide file tree
Showing 39 changed files with 200 additions and 195 deletions.
4 changes: 2 additions & 2 deletions docs/developers/UserBundle/Notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Sample usage

```php
$em = $this->getDoctrine()->getManager();
$currentUser = $this->container->get('security.context')->getToken()->getUser();
$currentUser = $this->container->get('security.token_storage')->getToken()->getUser();
$author = $this->getDoctrine()->getRepository('OjsUserBundle:User')->findOneBy(array('username' => 'demo_author'));
$txt = 'You can login as ' . $currentUser->getUsername();
// add notification
Expand All @@ -17,4 +17,4 @@ $n->setAction('attorney');
$n->setLevel(\Ojs\UserBundle\Entity\Param\NotificationParams::LEVEL_CONFIRMATION);
$em->persist($n);
$em->flush();
```
```
3 changes: 1 addition & 2 deletions src/Ojs/CliBundle/Command/IndexArticlesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$kernel = $this->getContainer()->get('kernel');
$application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$application->setAutoExit(false);
$output->writeln('<info>Index ' . ($journalId ? 'of journal#' . $journalId : 'all') . ' articles</info>');
$output->writeln('<info>Index '.($journalId ? 'of journal#'.$journalId : 'all').' articles</info>');

$output->writeln("\nDONE\n");
}

}
47 changes: 24 additions & 23 deletions src/Ojs/CliBundle/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use \Ojs\UserBundle\Entity\Role;
use \Ojs\UserBundle\Entity\User;
use Ojs\UserBundle\Entity\Role;
use Ojs\UserBundle\Entity\User;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
use Composer\Script\CommandEvent;

class InstallCommand extends ContainerAwareCommand {
class InstallCommand extends ContainerAwareCommand
{

protected function configure()
{
Expand All @@ -30,7 +31,8 @@ public static function composer(CommandEvent $event)
$webDir = $options['symfony-web-dir'];

if (!is_dir($webDir)) {
echo 'The symfony-web-dir (' . $webDir . ') specified in composer.json was not found in ' . getcwd() . ', can not install assets.' . PHP_EOL;
echo 'The symfony-web-dir ('.$webDir.') specified in composer.json was not found in '.getcwd().', can not install assets.'.PHP_EOL;

return;
}

Expand All @@ -45,7 +47,7 @@ protected static function getOptions(CommandEvent $event)
'symfony-assets-install' => 'hard',
), $event->getComposer()->getPackage()->getExtra());

$options['symfony-assets-install'] = getenv('SYMFONY_ASSETS_INSTALL') ? : $options['symfony-assets-install'];
$options['symfony-assets-install'] = getenv('SYMFONY_ASSETS_INSTALL') ?: $options['symfony-assets-install'];

$options['process-timeout'] = $event->getComposer()->getConfig()->get('process-timeout');

Expand All @@ -65,12 +67,12 @@ protected static function getPhp()
protected static function executeCommand(CommandEvent $event, $appDir, $cmd, $timeout = 300)
{
$php = escapeshellarg(self::getPhp());
$console = escapeshellarg($appDir . '/console');
$console = escapeshellarg($appDir.'/console');
if ($event->getIO()->isDecorated()) {
$console .= ' --ansi';
}

$process = new Process($php . ' ' . $console . ' ' . $cmd, null, null, null, $timeout);
$process = new Process($php.' '.$console.' '.$cmd, null, null, null, $timeout);
$process->run(function ($type, $buffer) {
echo $buffer;
});
Expand All @@ -91,13 +93,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$application->setAutoExit(false);
//$translator->setLocale('tr_TR');
$output->writeln($this->printWelcome());
$output->writeln('<info>' .
$translator->trans('ojs.install.title') .
$output->writeln('<info>'.
$translator->trans('ojs.install.title').
'</info>');

if (!$dialog->askConfirmation(
$output, '<question>' .
$translator->trans("ojs.install.confirm") .
$output, '<question>'.
$translator->trans("ojs.install.confirm").
' (y/n) : </question>', true
)) {
return;
Expand All @@ -113,28 +115,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
$application->run(new \Symfony\Component\Console\Input\StringInput($command3));
$output->writeln("Locations inserted.");

$output->writeln($sb . 'Inserting roles to db' . $se);
$output->writeln($sb.'Inserting roles to db'.$se);
$this->insertRoles($this->getContainer(), $output);

$admin_username = $dialog->ask(
$output, '<info>Set system admin username (admin) : </info>', 'admin');
$admin_email = $dialog->ask(
$output, '<info>Set system admin email' .
$output, '<info>Set system admin email'.
' ([email protected]) : </info>', '[email protected]');
$admin_password = $dialog->ask(
$output, '<info>Set system admin password (admin) </info>', 'admin');

$output->writeln($sb . 'Inserting system admin user to db' . $se);
$this->insertAdmin($this->getContainer(), $admin_username, $admin_email, $admin_password);
$output->writeln($sb.'Inserting system admin user to db'.$se);
$this->insertAdmin($this->getContainer(), $admin_username, $admin_email, $admin_password);

$output->writeln($sb . 'Inserting default theme record' . $se);
$output->writeln($sb.'Inserting default theme record'.$se);
$this->insertTheme($this->getContainer());

$output->writeln("\nDONE\n");
$output->writeln("You can run "
. "<info>php app/console ojs:install:initial-data </info> "
. "to add initial data\n");
}
."<info>php app/console ojs:install:initial-data </info> "
."to add initial data\n");
}

/**
* add default roles
Expand All @@ -150,11 +152,11 @@ public function insertRoles($container, OutputInterface $output)
$new_role = new Role();
$check = $role_repo->findOneByRole($role['role']);
if (!empty($check)) {
$output->writeln('<error> This role record already exists on db </error> : <info>' .
$role['role'] . '</info>');
$output->writeln('<error> This role record already exists on db </error> : <info>'.
$role['role'].'</info>');
continue;
}
$output->writeln('<info>Added : ' . $role['role'] . '</info>');
$output->writeln('<info>Added : '.$role['role'].'</info>');
$new_role->setName($role['desc']);
$new_role->setRole($role['role']);
$new_role->setIsSystemRole($role['isSystemRole']);
Expand Down Expand Up @@ -206,5 +208,4 @@ protected function printWelcome()
{
return '';
}

}
9 changes: 4 additions & 5 deletions src/Ojs/CliBundle/Command/InstallTestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
$application->run(new \Symfony\Component\Console\Input\StringInput($command3));
$output->writeln("Locations inserted.");

$output->writeln($sb . 'Inserting roles to db' . $se);
$output->writeln($sb.'Inserting roles to db'.$se);
$installCommand = new InstallCommand();
$installCommand->insertRoles($this->getContainer(), $output);
$output->writeln($sb . 'Inserting system admin user to db' . $se);
$output->writeln($sb.'Inserting system admin user to db'.$se);
$installCommand->insertAdmin($this->getContainer(), $admin_username, $admin_email, $admin_password);
$output->writeln("\nDONE\n");
$output->writeln("You can run "
. "<info>sudo php app/console ojs:install:initial-data</info> "
. "to add sample data\n");
."<info>sudo php app/console ojs:install:initial-data</info> "
."to add sample data\n");
}

}
3 changes: 1 addition & 2 deletions src/Ojs/CliBundle/Command/JobManagerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$kernel = $this->getContainer()->get('kernel');
$application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$application->setAutoExit(false);
$output->writeln('<info>Adding command ' . $command . '</info>');
$output->writeln('<info>Adding command '.$command.'</info>');
$job = new \JMS\JobQueueBundle\Entity\Job($command, $options);
$em->persist($job);
$em->flush($job);

$output->writeln("\nDONE\n");
}

}
26 changes: 13 additions & 13 deletions src/Ojs/CliBundle/Command/Jobs/CommonStatsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use \Ojs\JournalBundle\Entity\Sums;
use Ojs\JournalBundle\Entity\Sums;

class CommonStatsCommand extends ContainerAwareCommand {
class CommonStatsCommand extends ContainerAwareCommand
{

protected function configure()
{
Expand All @@ -32,14 +33,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

/**
* @param Doctrine\ORM\EntityManager $em
* @param string $entityName
* @param integer $count
* @param Doctrine\ORM\EntityManager $em
* @param string $entityName
* @param integer $count
* @return \Ojs\JournalBundle\Entity\Sums
*/
private function saveSum($em, $entityName, $count)
{
$check = $em->getRepository("OjsJournalBundle:Sums")->findOneBy(array('entity'=>$entityName));
$check = $em->getRepository("OjsJournalBundle:Sums")->findOneBy(array('entity' => $entityName));
$sum = $check ? $check : (new Sums());
$sum->setEntity($entityName);
$sum->setSum($count);
Expand All @@ -48,24 +49,23 @@ private function saveSum($em, $entityName, $count)
}

/**
*
* @param Doctrine\ORM\EntityManager $em
* @param string $entityName
* @param OutputInterface $output
*
* @param Doctrine\ORM\EntityManager $em
* @param string $entityName
* @param OutputInterface $output
* @return integer
*/
private function countSaveEntity($em, $entityName, $output)
{
$output->write("<info>Counting " . $entityName . "</info> ");
$output->write("<info>Counting ".$entityName."</info> ");
$count = $em->createQueryBuilder()
->select('count(entity.id)')
->from($entityName, 'entity')
->getQuery()->getSingleScalarResult();
$output->writeln(" <info> Result : " . $count . "</info>");
$output->writeln(" <info> Result : ".$count."</info>");
$output->writeln("<info>Saving count result to OjsJournalBundle:Sums");
$this->saveSum($em, $entityName, $count);

return $count;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Ojs\JournalBundle\Entity\Subject;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -20,7 +19,7 @@ protected function configure()

/**
* @todo not implemented yet
* @param InputInterface $input
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -34,15 +33,14 @@ protected function execute(InputInterface $input, OutputInterface $output)

foreach ($subjects as $subject) {
/** @var Subject $subject */
if($subject->getJournals()) {
$count = $subject->getJournals()->count();
$subject->setTotalJournalCount($count);
if ($subject->getJournals()) {
$count = $subject->getJournals()->count();
$subject->setTotalJournalCount($count);
$subject->setUpdatedBy("System");
$em->persist($subject);
$em->flush();
}
$em->persist($subject);
$em->flush();
}
echo ".";
}
}

}
6 changes: 3 additions & 3 deletions src/Ojs/CliBundle/Command/SampleDataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use \Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Input\StringInput;

class SampleDataCommand extends ContainerAwareCommand {
class SampleDataCommand extends ContainerAwareCommand
{

protected function configure()
{
Expand All @@ -33,5 +34,4 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->writeln("\nDONE\n");
}

}
Loading

0 comments on commit 217514a

Please sign in to comment.