How can I debug my command controller? - typo3

I have created a command controller and registered it on my scheduler, like:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] =
'Blog\\Events\\Command\\UpdateCommandController';
I can execute my command with the scheduler; but, if I enter a var_dump or die in my UpdateCommandController, I will not see any change in TYPO3 backend.
How can debug my command controller. And, what is the correct way to do this?
Can someone give me a tip?
Here is command controller, which i will to debug:
namespace Blog\Events\Command;
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
class UpdateCommandController extends CommandController
{
/**
* Eventsrepository
*
* #var \Blog\Events\Domain\Repository\EventsRepository
* #inject
*/
protected $eventsRepository;
public function updateCommand()
{
echo "hello world";
}
}

You can debug the controller by calling it from the command line. To do this, you need a backend user _cli_lowlevel (with no privileges).
Then you can execute the script typo3/cli_dispatch.phpsh using php. To execute your command controller, you need to execute a command similar to this:
php typo3/cli_dispatch.phpsh extbase <controller-name>:<action-name>
Both <controller-name> and <action-name> would be update in your case. To see all available actions from CommandControllers, execute this command:
php typo3/cli_dispatch.phpsh extbase help

You can use Typo3 extension Developer Log for debuging.
Extension create log records in the database and show them in backend module.
Example of use in Extbase PHP code:
$arguments = 'any-data-for-log';
\TYPO3\CMS\Core\Utility\GeneralUtility::devlog(
'[ClassName::functionName]',
'extension_name',
1, // severity
array('arguments' => $arguments) // log data
);
This is a better way (for me).

In TYPO3 9 and above you can log like this:
$this->logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
$logWriter = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\Writer\FileWriter', ['logFile' => 'typo3temp/logs/my_import.log']);
$this->logger->addWriter(\TYPO3\CMS\Core\Log\LogLevel::INFO, $logWriter);
and then
$this->logger->error($e->getMessage());

Related

Symfony Console Commands in scheduler in TYPO3 8

I wrote a symfony controller command which works as expected in cli. But I would prefer to trigger the script via scheduler. Is there a possibility to get the symfony command in the tasks of scheduler? (TYPO3 8)
You have to create your own task for scheduler as described in documentation of EXT:scheduler https://docs.typo3.org/c/typo3/cms-scheduler/master/en-us/DevelopersGuide/CreatingTasks/Index.html
class MyTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
public function execute() {
$businessLogic = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Vendor\Extension\BusinessLogic::class);
$businessLogic->run(arg1, arg2, …);
}
}

How to add my own custom class in Laravel 5?

Ok, in laravel 4, if I want to add my own custom class, eg : library\myFunction.php then I do the following steps :
add "myFunctions.php" into app/library/myFunctiosn.php
at app/start/global.php , within ClassLoader::addDirectories(array( , I add app_path().'/library',
And to call it within my blade view, I add the following codes
<?php
$FmyFunctions1 = new myFunctions;
$is_ok1=($FmyFunctions1->is_ok());
?>
The contents of app/library/myFunctions.php is :
<?php namespace App\library {
class myFunctions {
public function is_ok() {
return 'myFunction is OK';
}
}
}
?>
And it works.
But how to do so in Laravel 5 ???
PS : I read What are the best practices and best places for laravel 4 helpers or basic functions?
And tried to add "app/library/", to the autoload array and run composer dum-autoload , but it keeps give me error :
FatalErrorException in xxxx line xx: Class 'myFunctions' not found
I'm also already trying to use :
composer update
composer dump-autoload
php artisan dump
php artisan clear-compiled
php artisan dump-autoload
php artisan optimize
php artisan route:clear
php artisan route:scan
php artisan route:list
But still doesn't work...
This should help you.
FYI:
Basically, you could create another directory within app, and then namespace your files in there as appropriate:
app/CustomStuff/CustomDirectory/SomeClass.php.
Then, within your SomeClass.php, make sure you namespace it:
<?php
namespace App\CustomStuff\CustomDirectory;
class Someclass {}
Now, you can access this class using the namespace within your classes:
use App\CustomStuff\CustomDirectory\SomeClass;
After some trial and error, I found the answer.
There is no need to modify Composer. Just modify the Blade into:
<?php
$FmyFunctions1 = new \App\library\myFunctions;
$is_ok = ($FmyFunctions1->is_ok());
?>

Missing argument 2 for Illuminate when using command line to create controller

I am trying to create controller using the command line in laravel but when i SSH to my server and try to run the laravel CLI command php artisan controller:make AboutController
or even any other command like : php artisan list
I always get this message :
{
"error":
{
"type":"ErrorException",
"message":"Missing argument 2 for Illuminate\\Routing\\Router::controller(), called in \/home1\/jokira\/public_html\/laravel\/bootstrap\/compiled.php on line 3155 and defined","file":"\/home1\/jokira\/public_html\/laravel\/bootstrap\/compiled.php","line":4379
}
}
What am i doing wrong ?
Maybe you add some wrong routes to app/routes.php just like what I did.
I add some temp route like this:
//user routes
Route::get('/login');
Route::post('/login');
Route::get('/reg');
Route::post('/reg');
And I got the same errors as you .
After I deleted this lines , all works fine now.
Wish can help you .
You need to specify the path of the route for your controller.
This is wrong example:
Route::controller('AuthController');
And this is the correct one:
Route::controller('/auth', 'AuthController');

how to configure doctrine command line tools on zenframework 2

i am using doctrine 2 on zendframework 2. i have configured both correcly and they are both working.
i however wish to use doctrine's command line tool to generate entities etc.
i have followed doctrine's instructions and created a cli-config.php page in the root of my application:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/configuration.html
i am however lost on two issues;
the configuration requires a bootstrap php page; however, zendframework 2 does not use a bootstrap page; so what would the equivalent be?
Secondly, it requires us to obtain an entity mangager; would the method below be the correct way to get the entity manager:
public function getEntityManager()
{
if (null === $this->em) {
$this->em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
}
return $this->em;
}
below is how the cli-config.php page should look;
// cli-config.php
require_once 'my_bootstrap.php';
// Any way to access the EntityManager from your application
$em = GetMyEntityManager();
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));
i would really appreciate any help or advice on this matter.
warm regards
Andreea
the matter has been resolved:!!
it did not work because i was using a cygdrive command line. however, when i switched to git bash it worked perfectly. with git bash i have to use the command:
C: > cd project-directory
project-dir > vendor\bin\doctrine-module orm:validate-schema
If you have started your project using the Zend Skeleton Application you do have a composer.json file. You just need to include the DoctrineORMModule (instructions here)
Then, using the CMD just type
C: > cd project-directory
project-dir > vendor\bin\doctrine-module orm:validate-schema
There you go.
Once you have set up doctrine2 and zf2, you should be able to simply run all CLI commands.
php public/index.php orm:generate-entities
Using the parameters as described in the official documentation.
Note: DoctrineModule and DoctrineORMModule need to be enabled within your application.config.php
You need to install the doctrine/doctrine-orm-module with your Composer dependency manager. To do that, cd to your web site's top-level directory and type the following command:
php composer.phar require doctrine/doctrine-orm-module *
After executing this command, the DoctrineModule and DoctrineOrmModule will be installed into your vendor folder, and Doctrine commands will become available.
For more information about DoctrineOrmModule, see this:
https://github.com/doctrine/DoctrineORMModule

Do I need to enable javascript for PhantomJS when using Selenium Webdriver?

I have a testsuite in NUnit running on both IE and Chrome webdrivers. But when I wanted to try headerless PhantomJS (Ghostdriver) I can't get it to excute the actions I want to perform.
Having issues with easy stuff like
[TestFixture]
class PhantomJSTest{
protected IWebDriver driver;
[SetUp]
public void Setup() {
driver = new PhantomJSDriver(#"..\..\..\..");
}
[Test]
public void PhantomTest() {
driver.Navigate().GoToUrl(adress);
driver.FindElement(selector).Click();
}
[TearDown]
public void Teardown() {
driver.Close();
driver.Quit();
}
}
When the click is performed something should be set in my db, so when going back to that page manually I should be able to see it. The NUnit test itself is set to succeeded, but the action never happens. This is especially apparent when trying to do something based on the earlier action. Any help would be appreciated! =)
I would recommend you following activities:
1) try to relaunch your selenium hub with node(-s) based on phantomJs.
2) try to use instead of
driver.Navigate().GoToUrl(adress);
this one:
driver.get(URL);
driver.findElement(selector).click();
3) also see phantomJs documentation to get all phantomJs capabilities:
GhostDriver extra Capabilities
phantomjs.page.settings.SETTING = VALUE - Configure page.settings on
PhantomJS internal page objects (windows in WebDriver context) . Reference
phantomjs.page.customHeaders.HEADER = VALUE - Add extra HTTP Headers
when loading a URL . Reference
PhantomJSDriver (Java-binding) Capabilities
phantomjs.binary.path - Specify path to PhantomJS executable to use
phantomjs.ghostdriver.path - Specify path to GhostDriver main/src.js
script to use; allows to use a different version of GhostDriver then
the one embed in PhantomJS
phantomjs.cli.args - Specify command line arguments to pass to the
PhantomJS executable
phantomjs.ghostdriver.cli.args - Specify command line argument to
pass to GhostDriver (works only in tandem with
phantomjs.ghostdriver.path)
More details one can get at GhostDriver page
Also look through phantomJs command line options . This info might be helpful for you as well.
Hope this helps you.