protected function run()
    {
        if (empty($this->getOption('key')) || empty($this->getOption('secret'))) {
            return new Report(Report::TYPE_ERROR, 'Not all arguments were provided. Try to run the script with -h option');
        }

        $consumerService = $this->getClassService();
        $clazz = $this->getClass(ConsumerService::CLASS_URI);

        $label = $this->hasOption('label') ? $this->getOption('label') : $consumerService->createUniqueLabel($clazz);

        try {
            $consumer = $consumerService->createInstance($clazz, $label);
        } catch (\Exception $e) {
            return new Report(Report::TYPE_ERROR, 'Error while creating consumer. Actual message is: ' . $e->getMessage());
        }

        $consumer->setPropertyValue($this->getProperty(DataStore::PROPERTY_OAUTH_KEY), $this->getOption('key'));
        $consumer->setPropertyValue($this->getProperty(DataStore::PROPERTY_OAUTH_SECRET), $this->getOption('secret'));

        if ($this->hasOption('callbackUrl')) {
            $consumer->setPropertyValue($this->getProperty(DataStore::PROPERTY_OAUTH_CALLBACK), $this->getOption('callbackUrl'));
        }

        return new Report(Report::TYPE_SUCCESS, sprintf('Lti consumer "%s" was created. Check GUI to edit its properties', $consumer->getLabel()));
    }
protected function run()
    {
        if (empty($this->getOption('key')) || empty($this->getOption('secret'))) {
            return new Report(Report::TYPE_ERROR, 'Not all arguments were provided. Try to run the script with -h option');
        }

        $consumerService = $this->getClassService();
        $clazz = $this->getClass(ConsumerService::CLASS_URI);

        $label = $this->hasOption('label') ? $this->getOption('label') : $consumerService->createUniqueLabel($clazz);

        try {
            $consumer = $consumerService->createInstance($clazz, $label);
        } catch (\Exception $e) {
            return new Report(Report::TYPE_ERROR, 'Error while creating consumer. Actual message is: ' . $e->getMessage());
        }

        $consumer->setPropertyValue($this->getProperty(DataStore::PROPERTY_OAUTH_KEY), $this->getOption('key'));
        $consumer->setPropertyValue($this->getProperty(DataStore::PROPERTY_OAUTH_SECRET), $this->getOption('secret'));

        if ($this->hasOption('callbackUrl')) {
            $consumer->setPropertyValue($this->getProperty(DataStore::PROPERTY_OAUTH_CALLBACK), $this->getOption('callbackUrl'));
        }

        return new Report(Report::TYPE_SUCCESS, sprintf('Lti consumer "%s" was created. Check GUI to edit its properties', $consumer->getLabel()));
    }
protected function run ( ) { if ( empty ( $ this -> getOption ( 'key' ) ) || empty ( $ this -> getOption ( 'secret' ) ) ) { return new Report ( Report :: TYPE_ERROR , 'Not all arguments were provided. Try to run the script with -h option' ) ; } $ consumerService = $ this -> getClassService ( ) ; $ clazz = $ this -> getClass ( ConsumerService :: CLASS_URI ) ; $ label = $ this -> hasOption ( 'label' ) ? $ this -> getOption ( 'label' ) : $ consumerService -> createUniqueLabel ( $ clazz ) ; try { $ consumer = $ consumerService -> createInstance ( $ clazz , $ label ) ; } catch ( \ Exception $ e ) { return new Report ( Report :: TYPE_ERROR , 'Error while creating consumer. Actual message is: ' . $ e -> getMessage ( ) ) ; } $ consumer -> setPropertyValue ( $ this -> getProperty ( DataStore :: PROPERTY_OAUTH_KEY ) , $ this -> getOption ( 'key' ) ) ; $ consumer -> setPropertyValue ( $ this -> getProperty ( DataStore :: PROPERTY_OAUTH_SECRET ) , $ this -> getOption ( 'secret' ) ) ; if ( $ this -> hasOption ( 'callbackUrl' ) ) { $ consumer -> setPropertyValue ( $ this -> getProperty ( DataStore :: PROPERTY_OAUTH_CALLBACK ) , $ this -> getOption ( 'callbackUrl' ) ) ; } return new Report ( Report :: TYPE_SUCCESS , sprintf ( 'Lti consumer "%s" was created. Check GUI to edit its properties' , $ consumer -> getLabel ( ) ) ) ; }
Run the script
Run the script