How to use DataHandler in Symfony command controller in TYPO3 - typo3

class RemoveHiddenPages extends Symfony\Component\Console\Command\Command
{
protected function execute(InputInterface $input, OutputInterface $output)
{
Bootstrap::initializeBackendAuthentication();
$uid = someuid;
$cmd['pages'][$uid]['delete'] = 1;
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->start([], $cmd);
$dataHandler->process_cmdmap();
// ....
I try to run the command from the command line. This results in an exception:
Tue, 17 Mar 2020 10:14:15 +0100 [CRITICAL] request="684c29a15bc6b" component="TYPO3.CMS.Core.Error.DebugExceptionHandler":
Core: Exception handler (CLI): Uncaught TYPO3 Exception: Argument 1 passed to
TYPO3\CMS\Core\Session\Backend\DatabaseSessionBackend::update() must be of the type string, null given,
called in /site/typo3/sysext/core/Classes/Authentication/AbstractUserAuthentication.php on line 1311
| TypeError thrown in file /site/typo3/sysext/core/Classes/Session/Backend/DatabaseSessionBackend.php in line 159
- {"exception":{"xdebug_message":"\nTypeError: Argument 1 passed to
TYPO3\\CMS\\Core\\Session\\Backend\\DatabaseSessionBackend::update()
must be of the type string, null given, called in ....
In DataHandler::deletePages() a flash message is sent. This seems to cause the problem, as the session is not initialized. Is it possible to use the DataHandler in command controllers?
The example is based on:
https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/CommandControllers/Index.html
https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Typo3CoreEngine/UsingDataHandler/Index.html
I am using TYPO3 9.5.14

You can have a look into in2code/migration. There is a DataHandler call to move pages via symfony command: https://github.com/einpraegsam/migration/blob/master/Classes/Command/DataHandlerCommand.php
protected function execute(InputInterface $input, OutputInterface $output): int
{
$command = [];
$command['pages'][(int)$input->getArgument('startPid')][$input->getArgument('action')]
= (int)$input->getArgument('targetPid');
/** #var DataHandler $dataHandler */
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->BE_USER = $GLOBALS['BE_USER'];
$dataHandler->BE_USER->user['admin'] = 1;
$dataHandler->userid = $GLOBALS['BE_USER']->user['uid'];
$dataHandler->admin = true;
$dataHandler->bypassAccessCheckForRecords = true;
$dataHandler->copyTree = $input->getArgument('recursion');
$dataHandler->deleteTree = true;
$dataHandler->neverHideAtCopy = true;
$dataHandler->start([], $command);
$dataHandler->process_cmdmap();
$output->writeln($this->getMessage($dataHandler));
return 0;
}

Related

Unexpected data found during update on eloquent / Laravel

I am using ajax to update a model that contains timestamps, but it throw me an exception:
{message: "Unexpected data found.", exception: "InvalidArgumentException",…}
message: "Unexpected data found."
exception: "InvalidArgumentException"
file: "/home/asus/Devagnos/almada/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php"
line: 623
trace: [,…]
i have disabled the timestamps and i set the dateformat like this:
protected $dateFormat = 'Y-m-d H:i:s.u';
public $timestamps = false;
protected $dates = [
'created_at',
'updated_at'
];
alse I added these methods
/**
* #param $val
*/
public function setCreatedAtAttribute($val)
{
return Carbon::createFromFormat('Y-m-d H:i:s.u', $val);
}
/**
* #param $val
*/
public function setUpdatedAtAttribute($val)
{
return Carbon::createFromFormat('Y-m-d H:i:s.u', $val);
}
but I am always getting the same error, What am I doing wrong ?
I'm using laravel 6.8 and postgresql
If you're trying to use microseconds, then you should refer to this guide from the documentation:
https://carbon.nesbot.com/laravel/
I don't get what you tried with setCreatedAtAttribute and setUpdatedAtAttribute, setters are supposed to change the inner property, not to return a value.
Then check you gave to your DB columns enough precision (such as TIMESTAMP(6)) in your migration schemas.

The SOAP function called with localhost, works, when I call with external IP and port, returns Forbidden error

Function called:
public function getAcces($plngVersiune, $pstrNumeFirma, $pstrUtilizator, $pstrParolaSecurizata, $wsdl)
{
$this->plngVersiune = $plngVersiune;
$this->pstrNumeFirma = $pstrNumeFirma;
$this->pstrUtilizator = $pstrUtilizator;
$this->pstrParolaSecurizata = $pstrParolaSecurizata;
$this->wsdl = $wsdl;
$xml_array = array();
$xml_array['plngVersiune'] = $this->plngVersiune;
$xml_array['pstrNumeFirma'] = $this->pstrNumeFirma;
$xml_array['pstrUtilizator'] = $this->pstrUtilizator;
$xml_array['pstrParolaSecurizata'] = $this->pstrParolaSecurizata;
$client = new SoapClient($wsdl); // , array('trace' => $trace, 'exceptions' => $exceptions)
var_dump($client);
$clientToken = $client->LogIn($xml_array)->LogInResult;
var_dump($clientToken);
//unset($xml_array);
return $clientToken;
}
Line called:
$acces = $gru->getAcces(1,"ALM","Administrator","d41d8cd98f00b204e9800998ecf8427e", "http://82.108.151.XXX:8080/InterfacesWS/IInterfacesBO3.asmx?WSDL");
Returns Errors:
Fatal error: Uncaught SoapFault exception: [HTTP] Forbidden in C:\Program Files (x86)\Ampps\www\soap\class_01.php
SoapFault: Forbidden in C:\Program Files (x86)\Ampps\www\soap\class_01.php
Instead, if I call the same function with "http: //localhost/InterfacesWS/IInterfacesBO3.asmx? WSDL" I have no error. It works correctly.
How do I eliminate the SoapFault: Forbidden error?

unable to save PHP objects in mongodb

Getting 'zero-length keys are not allowed' FATAL error while saving object.
Is it due to presence of __construct() ?
I believe PHP object is allowed in save() method.
class Address{
private $name;
private $company;
private $zip;
public function __construct($name,$company,$zip){
$this->name = $name;
$this->company = $company;
$this->zip = $zip;
}
}
$newAddress = new Address("james","google",678);
print_r($newAddress);
// Address Object ( [name:Address:private] => james [company:Address:private] =>
// google [zip:Address:private] => 678 )
$addresses->save($newAddress);
Fatal error: Uncaught exception 'MongoException' with message 'zero-length keys are not allowed, did you use $ with double quotes?' in /var/www/html/index.php:105 Stack trace: #0 /var/www/html/index.php(105): MongoCollection->save(Object(Address)) #1 {main} thrown in /var/www/html/index.php on line 105
Umm, how do you expect mongo to read your private class variables.

Zend MultiDb resource

I have configured my application to work with multiple databases. The magic works just fine. In my Bootstrap.php I have defined the folowing:
protected function _initDb()
{
$resource = $this->getPluginResource('multidb');
Zend_Registry::set("multidb", $resource);
}
and in my application.ini:
resources.multidb.db1.adapter = mysqli
resources.multidb.db1.host = localhost
resources.multidb.db1.username = user
resources.multidb.db1.password = pass
resources.multidb.db1.dbname = db
resources.multidb.db1.charset= "utf8"
resources.multidb.db1.default= true
resources.multidb.db1.profiler.enabled = true
resources.multidb.oracle.adapter = oracle
resources.multidb.oracle.username = user
resources.multidb.oracle.password = pass
resources.multidb.oracle.charset= "utf8"
resources.multidb.oracle.dbname = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(Host = host.example.com) (Port = 1529)) (CONNECT_DATA = (SID = DB)))"
resources.multidb.oracle.profiler.enabled = true
All of this works just fine. In my models, I usually do something like this in the init():
$multidb = Zend_Registry::get("multidb");
$this->oracle = $multidb->getDb('oracle');
But I recently wanted to move this part to the Bootstrap, or rather, Registry, like this:
protected function _initDb()
{
$resource = $this->getPluginResource('multidb');
Zend_Registry::set("multidb", $resource);
Zend_Registry::set("odb",$resource->getDb('oracle'));
}
And this is what happened:
Fatal error: Uncaught exception 'Zend_Application_Resource_Exception' with message 'A DB adapter was tried to retrieve, but was not configured' in C:\Zend\Apache2\htdocs\Zend\Application\Resource\Multidb.php on line 135
I know a temporary fix around this, but why is this happening, and what could be a more long term fix, so that I could set each adapter in registry, preferably in bootstrap?
Thanks!
I think you have to make sure the multidb resource is bootstrapped in other to be filled. You can do this with the following:
protected function _initDb() {
$this->bootstrap('multidb');
$resource = $this->getPluginResource('multidb');
Zend_Registry::set("multidb", $resource);
Zend_Registry::set("odb",$resource->getDb('oracle'));
}

Symfony2 + DoctrineMongoDBBundle Configuration

I am trying to connect Symfony 2 with MongoDB in such way:
Register DoctrineMongoDBBundle in AppKernel::registerBundles
method
Set 'doctrine_mongo_db' configuration (see below config.yml)
Get 'doctrine.odm.mongodb.document_manager' from container in
HelloController action
And when I am trying to run the application MongoConnectionException is thrown.
Can anyone help me to solve this problem?
AppKernel.php
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\DoctrineMongoDBBundle\DoctrineMongoDBBundle(),
new Sensio\HelloBundle\HelloBundle()
);
return $bundles;
}
config.yml
framework:
charset: UTF-8
router: { resource: "%kernel.root_dir%/config/routing.yml" }
templating: { engines: ['twig'] }
## Doctrine Configuration
doctrine_mongo_db:
server: mongodb://root:root#192.168.0.111:27017
default_database: test
options: { connect: true }
mappings:
HelloBundle: { type: annotation, dir: Document }
# Twig Configuration
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
HelloController.php
/* #var $dm \Doctrine\ODM\MongoDB\DocumentManager */
$dm = $this->get('doctrine.odm.mongodb.document_manager');
Exception (line 96)
connecting to failed: Transport endpoint is not connected
in ~/vendor/doctrine-mongodb/lib/Doctrine/MongoDB/Connection.php line 96 »
93. if ($this->server) {
94. $this->mongo = new \Mongo($this->server, $this->options);
95. } else {
96. $this->mongo = new \Mongo();
97. }
The problem is in DoctrineMongoDBBundle configuration loading. The fix (https://github.com/fabpot/symfony/pull/740) should be merged soon.
For now you can use fixed method below.
public function load(array $configs, ContainerBuilder $container)
{
$mergedConfig = array();
foreach ($configs as $config) {
$mergedConfig = array_merge_recursive($mergedConfig, $config);
}
$this->doMongodbLoad($mergedConfig, $container);
}