Symfony2 + DoctrineMongoDBBundle Configuration - mongodb

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);
}

Related

SuiteCRM v7.10.29 Custom API v4.1

I am creating a custom API for SuiteCRM. When I attempt to run the new API from {CRM Home}/custom/service/v4_1_custom I receive an 'HTTP ERROR 500'. There are not errors in the error_log file or the SuiteCRM.log file.
I have followed the method in the following two url's
https://fayebsg.com/2013/05/extending-the-sugarcrm-api-updating-dropdowns/
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.0/Integration/Web_Services/Legacy_API/Extending_Web_Services/
registry.php
<?php
require_once('service/v4_1/registry.php');
class registry_v4_1_custom extends registry_v4_1
{
protected function registerFunction()
{
parent::registerFunction();
$this->serviceClass->registerFunction('test', array(), array());
}
}
SugarWebServicesImplv4_1_custom.php
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
require_once('service/v4_1/SugarWebServiceImplv4_1.php');
class SugarWebServiceImplv4_1_custom extends SugarWebServiceImplv4_1
{
/**
* #return string
*/
public function test()
{
LoggerManager::getLogger()->warn('SugerWebServiceImplv4_1_custom test()');
return ("Test Worked");
} // test
} // SugarWebServiceImplv4_1_custom
I found the answer to this issue.
In the file {SuiteCRM}/include/entryPoint.php there are many files that are included thru require_once. In this list of require_once files, there were 4 files that were set as require not require_once. These were classes and therefore could not be included a second time. I changed these to require_once and the HTTP Error 500 went away and the custom APIs started working.

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.

How to use DataHandler in Symfony command controller in 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;
}

Magento 2 - error creating db table from custom schema

I'm trying to create a custom module for Magento 2 and I've got to the point of defining the schema in the /Setup/InstallSchema.php
When running 'php bin/magento setup:upgrade' I get the error:
Call to undefined function Test/Connector/Setup/getConnection()
The module is enabled and correctly showing in the config file. The schema file I'm trying to run is:
<?php
namespace Test\Connector\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;
class InstallSchema implements InstallSchemaInterface
{
public function install(SchemaSetupInterface $setup, ModuleContextInterface
$context) {
$installer = $setup;
$installer->startSetup();
$tableName = $installer->getTable('test_connector_settings');
if ($installer->getConnection()->isTableExists($tableName) != true) {
$table = $installer->getConnection()
->newTable($installer->getTable('ipos_connector_settings'))
->addColumn('id', Table::TYPE_SMALLINT, null, ['identity'=> true, 'nullable'=>false, 'primary'=>true], 'ID')
->addColumn('api_url', Table::TYPE_TEXT, 255, ['nullable'=>true], 'API URL')
->addColumn('api_user', Table::TYPE_TEXT, 100, ['nullable'=>false], 'API User Name')
->addColumn('api_password', Table::TYPE_TEXT, 100, ['nullable'=>false], 'API Password');
$installer-getConnection()->createTable($table);
}
$installer->endSetup();
}
}
Thanks in advance,
Please change this line
$installer-getConnection()->createTable($table); // your code line.
With
$installer->getConnection()->createTable($table);

Symfony2 Fatal Error Class not found on AppKernel in Server

The project works in my local environment but when I deploy it on shared web server it doesn't work.
Server
/home
/app
/src
/gestor
/UsuarioBundle
...
/vendors
....
/public_html
/web
app.php
...
If I go to host/app.php ->
Fatal error:
Class 'Gestor\UsuarioBundle\UsuarioBundle' not found in /home/esdrhazc/app/AppKernel.php on line 19
AppKernel.php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Gestor\UsuarioBundle\UsuarioBundle(),
new Gestor\AdministracionBundle\AdministracionBundle(),
new Gestor\ExpedientesBundle\ExpedientesBundle(),
new Gestor\GestionBundle\GestionBundle(),
new \Ideup\SimplePaginatorBundle\IdeupSimplePaginatorBundle(),
new Gestor\MensajeBundle\MensajeBundle(),
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle()
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
Autoload.php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;
/**
* #var ClassLoader $loader
*/
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add('Gestor', __DIR__.'/../src');
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
And finally, for instance, class Usuario.php
namespace Gestor\UsuarioBundle\Entity;
...
class Usuario implements AdvancedUserInterface {...}
I have deleted server/app/cache and give permissions.
Thanks in advance!!!
Change the folder 'gestor' to 'Gestor'