Esempio n. 1
0
 protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output)
 {
     $jazzeeConfiguration = new \Jazzee\Configuration();
     $entityManager = $this->getHelper('em')->getEntityManager();
     $stub = new AdminStub();
     $stub = new AdminStub();
     $stub->em = $entityManager;
     $stub->config = $jazzeeConfiguration;
     $class = $jazzeeConfiguration->getAdminDirectoryClass();
     $directory = new $class($stub);
     $results = $directory->findByUniqueName($input->getArgument('user name'));
     if (count($results) == 0) {
         $output->write('<error>That user name is not in the directory.</error>' . PHP_EOL);
     } else {
         if (count($results) > 1) {
             $output->write('<error>This name is not unique in the directory.  It returned ' . count($results) . ' results.</error>' . PHP_EOL);
             $output->write('<error>The name belongs to:</error>' . PHP_EOL);
             foreach ($results as $arr) {
                 $output->write("<error>{$arr['lastName']}, {$arr['firstName']} ({$arr['emailAddress']})</error>" . PHP_EOL);
             }
         } else {
             $arr = $results[0];
             $user = new \Jazzee\Entity\User();
             $user->setUniqueName($arr['userName']);
             $user->setFirstName($arr['firstName']);
             $user->setLastName($arr['lastName']);
             $user->setEmail($arr['emailAddress']);
             $entityManager->persist($user);
             $entityManager->flush();
             $output->write("<info>{$arr['lastName']}, {$arr['firstName']} ({$arr['emailAddress']}) add as user #{$user->getId()}</info>" . PHP_EOL);
         }
     }
 }
Esempio n. 2
0
 protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output)
 {
     $jazzeeConfiguration = new \Jazzee\Configuration();
     if ($jazzeeConfiguration->getAdminDirectoryClass() != '\\Jazzee\\AdminDirectory\\Local') {
         $output->write('<error>You can only user create-user when the adminDirectoryClass is set to Jazzee\\AdminDirectory\\Local</error>' . PHP_EOL);
     }
     $entityManager = $this->getHelper('em')->getEntityManager();
     $existingUsers = $entityManager->getRepository('Jazzee\\Entity\\User')->findByUniqueName($input->getArgument('user name'));
     if (count($existingUsers) == 0) {
         $user = new \Jazzee\Entity\User();
         $user->setUniqueName($input->getArgument('user name'));
         $user->setFirstName($input->getArgument('first name'));
         $user->setLastName($input->getArgument('last name'));
         $user->setEmail($input->getArgument('email'));
         $entityManager->persist($user);
         $entityManager->flush();
         $output->write("<info>New user #{$user->getId()} created</info>" . PHP_EOL);
     } else {
         $output->write("<error>There is already a user with the name {$input->getArgument('user name')}</error>" . PHP_EOL);
     }
 }
Esempio n. 3
0
 protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output)
 {
     $jazzeeConfiguration = new \Jazzee\Configuration();
     $entityManager = $this->getHelper('em')->getEntityManager();
     $stub = new AdminStub();
     $stub->em = $entityManager;
     $stub->config = $jazzeeConfiguration;
     $class = $jazzeeConfiguration->getAdminDirectoryClass();
     $directory = new $class($stub);
     if (!$input->getOption('firstName') and !$input->getOption('lastName')) {
         $output->write('<error>You must specify at least one search term (firstName, lastName)</error>' . PHP_EOL);
     } else {
         $results = $directory->search($input->getOption('firstName'), $input->getOption('lastName'));
         $output->write('<info>Search returned ' . count($results) . ' results</info>' . PHP_EOL);
         if (count($results) > 50) {
             $output->write('<comment>Displaying the first 50 results</comment>' . PHP_EOL);
             $chunks = array_chunk($results, 50);
             $results = $chunks[0];
         }
         foreach ($results as $arr) {
             $output->write("<info>{$arr['lastName']}, {$arr['firstName']} ({$arr['emailAddress']}) has user name <comment>{$arr['userName']}</comment></info>" . PHP_EOL);
         }
     }
 }
Esempio n. 4
0
 /**
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output)
 {
     $error = false;
     $jazzeeConfiguration = new \Jazzee\Configuration();
     $entityManager = $this->getHelper('em')->getEntityManager();
     $stub = new AdminStub();
     $stub->em = $entityManager;
     $stub->config = $jazzeeConfiguration;
     $requiredExtensions = array('ldap', 'apc', 'curl', 'json', 'imagick', 'mbstring', 'xml', 'dom');
     $missing = array();
     foreach ($requiredExtensions as $re) {
         if (!extension_loaded($re)) {
             $missing[] = $re;
         }
     }
     if (count($missing)) {
         $error = true;
         foreach ($missing as $m) {
             $output->write("<error>The PHP {$m} extension is required and it is not installed.</error>" . PHP_EOL);
         }
     }
     //Check that the var direcotry is working
     $path = $jazzeeConfiguration->getVarPath() ? $jazzeeConfiguration->getVarPath() : __DIR__ . '/../../../var';
     if (!($realPath = \realpath($path)) or !\is_dir($realPath)) {
         if ($realPath) {
             $path = $realPath;
             //nicer error message if the path exists
         }
         $error = true;
         $output->write("<error>{$path} is does not exist so we cannot use it as the 'var' directory</error>" . PHP_EOL);
     }
     $perms = \substr(\sprintf('%o', \fileperms($realPath)), -4);
     $owner = \fileowner($realPath);
     $group = \filegroup($realPath);
     if (function_exists('posix_getpwuid')) {
         $arr = posix_getpwuid($owner);
         $owner = $arr['name'];
     }
     if (function_exists('posix_getgrgid')) {
         $arr = posix_getgrgid($group);
         $group = $arr['name'];
     }
     $output->write("<comment>{$realPath} is owned by {$owner}:{$group} and has permissions {$perms}.  Ensure your webserver can write to that directory</comment>" . PHP_EOL);
     //Check that the schema is correct
     $validator = new \Doctrine\ORM\Tools\SchemaValidator($entityManager);
     $errors = $validator->validateMapping();
     if ($errors) {
         $error = true;
         foreach ($errors as $className => $errorMessages) {
             $output->write("<error>The entity-class '" . $className . "' mapping is invalid:</error>" . PHP_EOL);
             foreach ($errorMessages as $errorMessage) {
                 $output->write('* ' . $errorMessage . PHP_EOL);
             }
             $output->write(PHP_EOL);
         }
     }
     if (!$validator->schemaInSyncWithMetadata()) {
         $error = true;
         $output->write('<error>The database schema is not correct.  Run "setup update" to fix this.</error>' . PHP_EOL);
     }
     try {
         $entityManager->getConfiguration()->ensureProductionSettings();
         $entityManager->getConnection()->connect();
     } catch (\Exception $e) {
         $error = true;
         $output->writeln('<error>' . $e->getMessage() . '</error>');
     }
     if ($jazzeeConfiguration->getStatus() == 'DEVELOPMENT') {
         $error = true;
         $output->write("<error>Jazzee is in developer mode.</error>" . PHP_EOL);
     } else {
         //Check that the cache is setup
         if (!extension_loaded('apc')) {
             $error = true;
             $output->write("<error>APC is required for caching, but it it not installed.</error>" . PHP_EOL);
         }
         $metadatas = $entityManager->getMetadataFactory()->getAllMetadata();
         $path = $entityManager->getConfiguration()->getProxyDir();
         if (!is_dir($path)) {
             $directory = dirname($path);
             if (\realpath($directory)) {
                 $directory = \realpath($directory);
             }
             $base = basename($path);
             if (!\is_writable($directory)) {
                 $error = true;
                 $output->write("<error>We do not have permission to create directory {$base} in {$directory}</error>" . PHP_EOL);
             } else {
                 mkdir($path, 0777, true);
             }
         }
         if (!$error) {
             $proxyDir = \realpath($path);
             if (!\is_writable($proxyDir)) {
                 $error = true;
                 $output->write("<error>We do not have permission to write to {$proxyDir}.</error>" . PHP_EOL);
             } else {
                 $entityManager->getProxyFactory()->generateProxyClasses($metadatas, $proxyDir);
             }
         }
         if (!apc_clear_cache() || !apc_clear_cache('user') || !apc_clear_cache('opcode')) {
             $output->write("<error>Error Clearning APC Cache</error>" . PHP_EOL);
         }
     }
     try {
         //Test the Authentication service
         $class = $jazzeeConfiguration->getAdminAuthenticationClass();
         $adminAuthentication = new $class($stub);
         if (!$adminAuthentication instanceof \Jazzee\Interfaces\AdminAuthentication) {
             $error = true;
             $output->write("<error>{$class} does not implement AdminAuthentication Interface.</error>" . PHP_EOL);
         }
         //Test the directory service
         $class = $jazzeeConfiguration->getAdminDirectoryClass();
         $adminDirectory = new $class($stub);
         if (!$adminDirectory instanceof \Jazzee\Interfaces\AdminDirectory) {
             $error = true;
             $output->write("<error>{$class} does not implement AdminDirectory Interface.</error>" . PHP_EOL);
         }
         //          This isn't available until we can limit the search returned Issue #90
         //          $attributes = array(
         //              $jazzeeConfiguration->getLdapLastNameAttribute() => '*'
         //          );
         //          $results = $adminDirectory->search($attributes);
     } catch (\Jazzee\Exception $e) {
         $error = true;
         $output->writeln('<error>' . $e->getMessage() . '</error>');
     }
     if (!class_exists('HTMLPurifier')) {
         $error = true;
         $output->write("<error>HTML Purifier is required and it is not installed.</error>" . PHP_EOL);
     }
     if (!class_exists('\\Doctrine\\ORM\\Version')) {
         $error = true;
         $output->write("<error>Doctrine ORM is required and it is not installed.</error>" . PHP_EOL);
     }
     if (!class_exists('\\Monolog\\Logger')) {
         $error = true;
         $output->write("<error>Monolog is required and it is not installed.</error>" . PHP_EOL);
     }
     if ($error) {
         $output->write(PHP_EOL . "<error>Preflight Check Failed</error>" . PHP_EOL);
     } else {
         $output->write(PHP_EOL . "<info>Preflight Check Passed</info>" . PHP_EOL);
     }
 }