public function populateElasticSearchIndices()
 {
     $application = new \Symfony\Bundle\FrameworkBundle\Console\Application(self::$kernel);
     $application->setAutoExit(false);
     $options = new \Symfony\Component\Console\Input\StringInput('fos:elastica:populate --quiet');
     $application->run($options);
 }
 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>Ojs Test Installation</info>');
     $output->writeln('<info>Updating db schema!</info>');
     $application->run(new \Symfony\Component\Console\Input\StringInput('doctrine:schema:update --force --quiet'));
     $admin_username = '******';
     $admin_email = '*****@*****.**';
     $admin_password = '******';
     $sb = '<fg=black;bg=green>';
     $se = '</fg=black;bg=green>';
     $location = $this->getContainer()->get('kernel')->getRootDir() . '/../src/Ojs/LocationBundle/Resources/data/location.sql';
     $locationSql = \file_get_contents($location);
     $command3 = 'doctrine:query:sql "' . $locationSql . '"';
     $application->run(new \Symfony\Component\Console\Input\StringInput($command3));
     $output->writeln("Locations inserted.");
     $output->writeln($sb . 'Inserting roles to db' . $se);
     $installCommand = new InstallCommand();
     $installCommand->setApplication($this->getApplication());
     $installCommand->insertRoles($output);
     $output->writeln($sb . 'Inserting system admin user to db' . $se);
     $installCommand->insertAdmin($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");
 }
 /**
  * Creates a Client.
  *
  * @param array $options An array of options to pass to the createKernel class
  * @param array $server  An array of server parameters
  *
  * @return Client A Client instance
  */
 protected static function createClient(array $options = array(), array $server = array())
 {
     if (!self::$internalClient) {
         self::$internalClient = parent::createClient($options, $server);
         if (self::$db_isolation) {
             /** @var Client $client */
             $client = self::$internalClient;
             //workaround MyISAM search tables are not on transaction
             if (self::$db_reindex) {
                 $kernel = $client->getKernel();
                 $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
                 $application->setAutoExit(false);
                 $options = array('command' => 'oro:search:reindex');
                 $options['--env'] = "test";
                 $options['--quiet'] = null;
                 $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
             }
             $client->startTransaction();
             $pdoConnection = Client::getPdoConnection();
             if ($pdoConnection) {
                 //set transaction level to 1 for entityManager
                 $connection = $client->createConnection($pdoConnection);
                 $client->getContainer()->set('doctrine.dbal.default_connection', $connection);
                 /** @var EntityManager $entityManager */
                 $entityManager = $client->getContainer()->get('doctrine.orm.entity_manager');
                 if (spl_object_hash($entityManager->getConnection()) != spl_object_hash($connection)) {
                     $reflection = new \ReflectionProperty('Doctrine\\ORM\\EntityManager', 'conn');
                     $reflection->setAccessible(true);
                     $reflection->setValue($entityManager, $connection);
                 }
             }
         }
     }
     return self::$internalClient;
 }
 /**
  * Not implemented yet
  * @todo not implemented yet
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $journalId = $input->getArgument('journal-id');
     $dialog = $this->getHelperSet()->get('dialog');
     $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("\nDONE\n");
 }
Beispiel #5
0
 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 initial data</info>');
     $application->run(new StringInput('h4cc_alice_fixtures:load:sets'));
     $output->writeln('<info>Adding initial workflow data</info>');
     // TODO: ORM Workflow initial data
     $output->writeln('<info>Recalculating precalculated fields</info>');
     $application->run(new StringInput('ojs:count:journals:subjects'));
     $output->writeln("\nDONE\n");
 }
Beispiel #6
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $command = $input->getArgument('action');
     $options = $input->getArgument('options');
     $em = $this->getContainer()->get('doctrine')->getManager();
     $kernel = $this->getContainer()->get('kernel');
     $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
     $application->setAutoExit(false);
     $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");
 }
Beispiel #7
0
 public function testGenerateWsse()
 {
     /** @var Kernel $kernel */
     $kernel = $this->client->getKernel();
     /** @var Application $application */
     $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
     $application->setAutoExit(false);
     $doctrine = $this->client->getContainer()->get('doctrine');
     /** @var Organization $organization */
     $organization = $doctrine->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $user = $this->client->getContainer()->get('oro_user.manager')->findUserByUsername('admin');
     $apiKey = $doctrine->getRepository('OroUserBundle:UserApi')->findOneBy(['user' => $user, 'organization' => $organization]);
     $command = new GenerateWSSEHeaderCommand();
     $command->setApplication($application);
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), '--env' => $kernel->getEnvironment(), 'apiKey' => $apiKey->getApiKey()));
     preg_match_all('/(^Authorization:\\s*(.*$))|(^X-WSSE:\\s*(.*$))/im', $commandTester->getDisplay(), $header);
     return $header;
 }
 /**
  * @Route("/translate/thispag")
  * @Method("POST")
  *
  * @Template()
  */
 public function thispageAction(Request $request)
 {
     if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $em = $this->getDoctrine()->getManager();
         $formData = $request->request->all();
         $formData = $formData['form']['translations'];
         for ($i = 0; $i < count($formData); $i++) {
             $transKey = $formData[$i]['transKey'];
             $transLocale = $formData[$i]['transLocale'];
             $messageDomain = $formData[$i]['messageDomain'];
             $translation = $formData[$i]['translation'];
             $trans = $this->get('doctrine')->getRepository('AsmTranslationLoaderBundle:Translation')->findOneBy(array('transKey' => $transKey, 'transLocale' => $transLocale, 'messageDomain' => $messageDomain));
             if (true === isset($trans) && true === is_object($trans) && $trans != null) {
                 $trans->setTranslation($translation);
                 $trans->setDateUpdated(new \DateTime());
                 $em->persist($trans);
                 $em->flush();
             }
         }
         $kernel = $this->get('kernel');
         $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
         $application->setAutoExit(false);
         $options = array('command' => 'doctrine:cache:clear-metadata');
         $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
         $options = array('command' => 'cache:clear');
         $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
         $options = array('command' => 'assets:install', "--symlink" => 'web');
         $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
         $options = array('command' => 'php app/console assetic:dump');
         $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
         $options = array('command' => 'asm:translations:dummy');
         $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
     }
     $session = $request->getSession();
     $lastroute = $session->get('last_route');
     if (false === isset($lastroute['name']) || trim($lastroute['name']) == "") {
         $lastroute['name'] = 'syw_front_main_main_index';
     }
     $url = $this->generateUrl($lastroute['name']);
     $response = new RedirectResponse($url);
     return $response;
 }
Beispiel #9
0
 /**
  * @param int $counter
  * @dataProvider dataSearchLoad
  */
 public function testSearchLoad($counter = 1)
 {
     //Load all fixtures
     $kernel = $this->client->getKernel();
     $container = $this->client->getContainer();
     $container->counter = $counter;
     $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
     $application->setAutoExit(false);
     $options = array('command' => AddFulltextIndexesCommand::COMMAND_NAME);
     $options['--env'] = "test";
     $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
     $options = array('command' => 'doctrine:fixtures:load');
     $options['--fixtures'] = __DIR__ . DIRECTORY_SEPARATOR . "Fixtures";
     $options['--env'] = "test";
     $options['--no-interaction'] = null;
     $options['--no-debug'] = null;
     list($msec, $sec) = explode(" ", microtime());
     $start = $sec + $msec;
     $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
     list($msec, $sec) = explode(" ", microtime());
     $stop = $sec + $msec;
     $counter = $counter * 3;
     echo "\nUploading execution time of {$counter} entities is " . round($stop - $start, 4) . " sec";
 }
 /**
  * Read plugins from the directory
  *
  * @Annotations\Delete("/cache")
  * @ApiDoc(
  *   description = "Clear the application cache.",
  *   resource = false,
  *   statusCodes = {
  *     200 = "Returned when cache has been cleared"
  *   }
  * )
  *
  * @return View
  */
 public function cacheClearAction()
 {
     $this->checkIsAdmin();
     $kernel = $this->get('kernel');
     $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
     $application->setAutoExit(false);
     $options = array('command' => 'cache:clear', "--env" => Globals::getEnv(), '--no-warmup' => true);
     return new JsonResponse(['cache' => $application->run(new \Symfony\Component\Console\Input\ArrayInput($options))]);
 }
Beispiel #11
0
/**
 * @param       $command
 * @param array $args
 *
 * @return array
 * @throws Exception
 */
function run_symfony_command($command, array $args)
{
    static $application;
    require_once MAUTIC_APP_ROOT . '/autoload.php';
    require_once MAUTIC_APP_ROOT . '/AppKernel.php';
    $args = array_merge(['console', $command], $args);
    if (null == $application) {
        $kernel = new \AppKernel('prod', true);
        $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
        $application->setAutoExit(false);
    }
    $input = new \Symfony\Component\Console\Input\ArgvInput($args);
    $output = new \Symfony\Component\Console\Output\NullOutput();
    $exitCode = $application->run($input, $output);
    unset($input, $output);
    return $exitCode === 0;
}
 /**
  * @Route("/hydra/youtube", name="virtual_identity_youtube_configure")
  * @Template()
  */
 public function configureAction()
 {
     $service = $this->get('virtual_identity_youtube');
     $configurationEntity = new ConfigurationEntity();
     $configurationEntity->setApiRequests($this->container->getParameter('virtual_identity_youtube.api_requests'));
     $configurationEntity->setConsumerKey($this->container->getParameter('virtual_identity_youtube.consumer_key'));
     $configurationEntity->setConsumerSecret($this->container->getParameter('virtual_identity_youtube.consumer_secret'));
     $configurationEntity->setToken($this->container->getParameter('virtual_identity_youtube.token'));
     $form = $this->createForm(new ConfigurationEntityType(), $configurationEntity);
     $form->handleRequest($this->getRequest());
     if ($form->isValid()) {
         $hydraConfigFile = $this->get('kernel')->getRootDir() . '/config/hydra.yml';
         if (file_exists($hydraConfigFile)) {
             $hydraConfig = Yaml::parse(file_get_contents($hydraConfigFile));
         } else {
             $hydraConfig = array();
         }
         $hydraConfig['virtual_identity_youtube']['api_requests'] = $configurationEntity->getApiRequests();
         $hydraConfig['virtual_identity_youtube']['consumer_key'] = $configurationEntity->getConsumerKey();
         $hydraConfig['virtual_identity_youtube']['consumer_secret'] = $configurationEntity->getConsumerSecret();
         $hydraConfig['virtual_identity_youtube']['token'] = $configurationEntity->getToken();
         // update runtime configuration
         $service->setAuthentication($configurationEntity->getConsumerKey(), $configurationEntity->getConsumerSecret(), $configurationEntity->getToken());
         $service->setApiRequests($configurationEntity->getApiRequests());
         // save changes
         file_put_contents($hydraConfigFile, Yaml::dump($hydraConfig, 3));
         // clear cache
         $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->get('kernel'));
         $application->setAutoExit(false);
         $options = array('command' => 'cache:clear');
         $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
     }
     return array('credentialsValid' => $service->isAccessTokenValid(), 'form' => $form->createView());
 }
 /**
  * @Route("/hydra/twitter", name="virtual_identity_twitter_configure")
  * @Template()
  */
 public function configureAction()
 {
     $service = $this->get('virtual_identity_twitter');
     $repository = $this->getDoctrine()->getManager()->getRepository('\\VirtualIdentity\\TwitterBundle\\Entity\\TwitterRequestEntity');
     $originalRequests = $repository->findAll();
     $configurationEntity = new ConfigurationEntity();
     $configurationEntity->setApiRequests($originalRequests);
     $configurationEntity->setConsumerKey($this->container->getParameter('virtual_identity_twitter.consumer_key'));
     $configurationEntity->setConsumerSecret($this->container->getParameter('virtual_identity_twitter.consumer_secret'));
     $configurationEntity->setToken($this->container->getParameter('virtual_identity_twitter.token'));
     $configurationEntity->setSecret($this->container->getParameter('virtual_identity_twitter.secret'));
     $entities = array();
     $em = $this->getDoctrine()->getManager();
     $meta = $em->getMetadataFactory()->getAllMetadata();
     foreach ($meta as $m) {
         if (!in_array('VirtualIdentity\\TwitterBundle\\Interfaces\\TwitterEntityInterface', class_implements($m->getName()))) {
             continue;
         }
         $entities[$m->getName()] = $m->getName();
     }
     $form = $this->createForm(new ConfigurationEntityType($entities), $configurationEntity);
     $form->handleRequest($this->getRequest());
     if ($form->isValid()) {
         $hydraConfigFile = $this->get('kernel')->getRootDir() . '/config/hydra.yml';
         if (file_exists($hydraConfigFile)) {
             $hydraConfig = Yaml::parse(file_get_contents($hydraConfigFile));
         } else {
             $hydraConfig = array();
         }
         //$hydraConfig['virtual_identity_twitter']['api_requests']    = $configurationEntity->getApiRequests();
         $hydraConfig['virtual_identity_twitter']['consumer_key'] = $configurationEntity->getConsumerKey();
         $hydraConfig['virtual_identity_twitter']['consumer_secret'] = $configurationEntity->getConsumerSecret();
         $hydraConfig['virtual_identity_twitter']['token'] = $configurationEntity->getToken();
         $hydraConfig['virtual_identity_twitter']['secret'] = $configurationEntity->getSecret();
         // update runtime configuration
         $service->setAuthentication($configurationEntity->getConsumerKey(), $configurationEntity->getConsumerSecret(), $configurationEntity->getToken(), $configurationEntity->getSecret());
         $service->setApiRequests($configurationEntity->getApiRequests());
         // save changes
         file_put_contents($hydraConfigFile, Yaml::dump($hydraConfig, 3));
         $em = $this->getDoctrine()->getManager();
         $removed = array();
         foreach ($configurationEntity->getApiRequests() as $request) {
             $em->persist($request);
         }
         foreach ($originalRequests as $oRequest) {
             $found = false;
             foreach ($configurationEntity->getApiRequests() as $request) {
                 if ($oRequest->getId() == $request->getId()) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 $em->remove($oRequest);
             }
         }
         $em->flush();
         // clear cache
         $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->get('kernel'));
         $application->setAutoExit(false);
         $options = array('command' => 'cache:clear');
         $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
     }
     return array('credentialsValid' => $service->isAccessTokenValid(), 'form' => $form->createView());
 }
 /**
  * refreshes the google access token if the current token is expired.
  * A refresh_token and a expire_date must be set in the config.
  *
  * @return string the new access token
  */
 public function refreshAccessToken()
 {
     $hydraConfigFile = $this->kernel->getRootDir() . '/config/hydra.yml';
     if (!file_exists($hydraConfigFile)) {
         return '';
     }
     $hydraConfig = Yaml::parse(file_get_contents($hydraConfigFile));
     if (!isset($hydraConfig['virtual_identity_youtube']['refresh_token']) || !isset($hydraConfig['virtual_identity_youtube']['consumer_key']) || !isset($hydraConfig['virtual_identity_youtube']['consumer_secret']) || !isset($hydraConfig['virtual_identity_youtube']['expire_date'])) {
         throw new ApiException('Refreshing the access token did not work, ' . 'because either no consumer_key, consumer_secret, expire_date or ' . 'refresh_token was found in app/config/hydra.yml');
     }
     if (time() < $hydraConfig['virtual_identity_youtube']['expire_date']) {
         return $hydraConfig['virtual_identity_youtube']['token'];
     }
     // send request for an access token
     $api = new \tmhOAuth();
     $status = $api->apponly_request(array('method' => 'POST', 'url' => 'https://accounts.google.com/o/oauth2/token', 'params' => array('client_id' => $this->authentication['consumer_key'], 'client_secret' => $this->authentication['consumer_secret'], 'grant_type' => 'refresh_token', 'refresh_token' => $hydraConfig['virtual_identity_youtube']['refresh_token'])));
     if ($status == 200) {
         // get the access token and store it in a cookie
         $response = json_decode($api->response['response'], true);
         $return = array('accessToken' => $response['access_token'], 'expiresIn' => $response['expires_in']);
     } else {
         throw new ApiException('Obtaining the refreshed access token did not work! Status code: ' . $status . '. Response was: ' . $api->response['response']);
     }
     $expireDate = time() + $return['expiresIn'] - 10;
     $hydraConfig['virtual_identity_youtube']['token'] = $return['accessToken'];
     $hydraConfig['virtual_identity_youtube']['expire_date'] = $expireDate;
     // save changes (must save first, so no endless loop happens)
     file_put_contents($hydraConfigFile, Yaml::dump($hydraConfig, 3));
     // update runtime configuration
     $this->setAuthentication($hydraConfig['virtual_identity_youtube']['consumer_key'], $hydraConfig['virtual_identity_youtube']['consumer_secret'], $return['accessToken']);
     // clear cache
     $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->kernel);
     $application->setAutoExit(false);
     $options = array('command' => 'cache:clear');
     $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
     return $return['accessToken'];
 }