gh-andi / userscan

This is a site which makes the user scan of owncloud manually triggerable
0 stars 0 forks source link

call php command instead of exec #1

Open felixboehm opened 7 years ago

felixboehm commented 7 years ago

You want to call this command, which is basically a Symfony\Component\Console\Command\Command https://github.com/owncloud/core/blob/master/core/Command/User/SyncBackend.php

Here is described how to call such a command directly via PHP: https://symfony.com/doc/current/console/command_in_controller.html

gh-andi commented 7 years ago

Thanks for pointing me in the right direction I've below added my code until now, but I always get that the issue: "PHP Fatal error: Uncaught Error: Class 'Symfony\Component\HttpKernel\KernelInterface' not found"

What do I need to change for the KernelInterface to be availible in my code ?

` <?php namespace AppBundle\Controller;

                    //Make kernael commands availible by using below frameworks
                    use Symfony\Bundle\FrameworkBundle\Console\Application;
                    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
                    use Symfony\Component\Console\Input\ArrayInput;
                    use Symfony\Component\Console\Output\BufferedOutput;
                    use Symfony\Component\HttpFoundation\Response;
                    use Symfony\Component\HttpFoundation\Request;
                    use Symfony\Component\HttpKernel\KernelInterface;
                    use Symfony\Component\EventDispatcher\EventDispatcher;
                    use Symfony\Component\HttpFoundation\RequestStack;
                    use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
                    use Symfony\Component\HttpKernel\Controller\ControllerResolver;

                    //Define The Class used to use the command
                    //class UserSyncBackendController extends Controller {

                            //Define the function used to execute the Command
                            function syncUserBackend(Kernelinterface $kernel){

                                    //Create an application using the kernel
                                    $application = new Application($kernel);
                                    $application->setAutoExit(false);

                                    //Create an input variable that will be sent to the kernel
                                    $input = new ArrayInput(array(

                                            //Define the message that will be sent to the kernel
                                            'comand' => "occ user:sync 'OCA\User_LDAP\User_Proxy' -m 'remove' -n",

                                            //Define the message limit if you want to limit the messages that are being sent
                                            //'--mesage-limit' => $message,

                                    ));

                                    //Create the output that will be filled with the output of the function
                                    $output = new BufferedOutput();

                                    //run the set up command on the kernel
                                    $application->run($input, $output);

                                    //Fetch the response of the command
                                    $content = $output->fetch();

                                    //Return the response
                                    return new Response($content);
                            }

?>

gh-andi commented 7 years ago

To be clear the issue get thrown when I tried to create a kernel object, to send it to the function

                    $kernel = new KernelInterface()
                    $userSyncResult = syncUserBackend($kernel);

                    echo $userSyncResult;
felixboehm commented 7 years ago

The userSync doesn't use any KernelInterface, this comes from the example, right?

https://github.com/owncloud/core/blob/master/core/Command/User/SyncBackend.php#L57

gh-andi commented 7 years ago

The project managment has decided against the helpdesk triggerable user scan, since then I haven't invested any time in to this

Still thank you for the help Felix