Apigility "Error saving field" while creating "db-connected" service - php

When I try to create a new service using db-connected in Apigility, I'm getting the error Error saving field. After receive the error, the service is created but if I select this one, I receive the error Unable to fetch service.
It seems to happen always when I create a db-connected service in a table with name containing "_".
The error that I'm getting in console is:
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (Hookit-V1-Rest-Vitrine_usuario-Controller, line 0)
I checked the module's config and the parameters are have been created.
in module's config in node zf-apigility O removed the parameter resource_class and the run the service... It worked.
but I can't sync the service in admin.
Does someone knows how to solve it to sync the service in Apigility's admin?

Alessandro Garcez is correct. This issue was resolved in this merge https://github.com/zfcampus/zf-apigility-admin-ui/pull/59
However, this merge has been overwritten and in the latest version, you will get the same issue. I have made a pull request to bring back the fix that Alessandro Garcez mentioned.

It seems that when the new service is created, if the table name contains an underscore ( _ ), the API will convert this to what looks like CamelCase.
But when the UI then wants to create the fields for this newly created service, it (the UI) will still use the tablename with the underscore in it, when accessing the api (/apigility/api/module//rest/--Rest--Controller/input-filter)
But the API will this time expect the controller-part being specified with the tablename camedcased:
(/apigility/api/module//rest/--Rest--Controller/input-filter)
It had already been fixed but was undone, I don't know why.
There is a opened discussion https://github.com/zfcampus/zf-apigility-admin-ui/issues/78.
For now is possible follow this way:
Change the function capitalizeFirstLetter in file src/apigility-ui/service/api.service.js adding the line var string = string.replace(/(\w)/g, function(,letter) { return letter.toUpperCase(); }); before the return.

Related

Service override doesn't work as expected

I create a service inside my module with the name of an existing core service (prestashop.adapter.data_provider.product). It successfully replaces it as seen in php ./bin/console debug:container output.
In yaml:
prestashop.adapter.data_provider.product:
class: PrestaShop\Module\MyModule\Adapter\Product\ProductDataProvider
The problem now is that I have 500 errors in some pages in BO. These errors are type errors like:
Type error: Argument 4 passed to
PrestaShopBundle\Model\Product\AdminModelAdapter::__construct() must
be an instance of
PrestaShop\PrestaShop\Adapter\Product\ProductDataProvider, instance of
PrestaShop\Module\MyModule\Adapter\Product\ProductDataProvider given,
called in....
I understand now that, whenever a constructor has an argument of type ProductDataProvider, the app tries to load my service but find a differentuse statement in the class (i.e in PrestaShopBundle\Model\Product\AdminModelAdapter)
These errors can be fixed by replacing the use statement in each file containing the problem, but as you may know, touching core files must be avoided.
Is there a way of overriding an existing service, but also make the override work all across the app "bypassing the use statements of the old service".

Add custom data to laravel log

I want for a certain Laravel Job class to change the behaviour of the logging system. This is how my logs look right now:
[2018-08-22 08:31:24] production.INFO: [do-harvester-job]
[template: 598 - theme: 2592]Doing tasks
This is achieved by the following code:
\Log::info("{$this->harvester_job->log_prefix()}Doing tasks");
The problem is that I have a lot of log calls like this one and it gets cumbersome to always add the call to the log_prefix method.
Is there any way of prepending that info to the log without having to concatenate it inside the log call?
If you are facing problems in displaying the class data inside log file then you can use json_encode($className->fetchAllData()).

Laravel 5 > Using monolog introspection processor

I have configured Laravel 5 to use a custom logging configuration (default is way too simple). I've added monolog's IntrospectionProcessor to log the file name and line number of the log call.
The problem is that all lines get the same file and line number:
[2015-06-29 17:31:46] local.DEBUG (/home/vagrant/project/vendor/laravel/framework/src/Illuminate/Log/Writer.php#201): Loading view... [192.168.10.1 - GET /loans/create]
Is there a way to config the IntrospectionProcessor to print the actual lines and not the facade ones?
If I do Log::getMonolog()->info('Hello'); it works and prints the correct file and line number... but I don't know how safe is to avoid calling the Writer.writeLog function because it fires a log event (is it safe to not fire that event?).
(Only tried in Laravel 4.2!)
When pushing the Introspection Processor to Monolog it is possible to give an skipClassesPartial array as second parameter in the IntrospectionProcessor contructor. With this array it is possible to skip the Laravel Illuminate classes and the logger logs the class calling the log method.
$log->pushProcessor(new IntrospectionProcessor(Logger::DEBUG, array('Illuminate\\')));
also see: https://github.com/Seldaek/monolog/blob/master/src/Monolog/Processor/IntrospectionProcessor.php
I know this is an old question but I thought I'd give a quick update because it's pretty easy to get this done now.
I haven't tried with Laravel but My own logging mechanism is within a LoggingService wrapper class. As such the introspection was only giving details about the service rather than the caller.
after reading Matt Topolski's answer, I had a look in the IntrospectionProcessor.php. the constructor looks like this:
__construct($level = Logger::DEBUG, array $skipClassesPartials = array(), $skipStackFramesCount = 0)
All I had to do was add the processor like this:
log->pushProcessor(new IntrospectionProcessor(Logger::DEBUG, array(), 1));
This is actually the expected functionality unless you're having the handler process the logs directly (check out the comments at the top of IntrospectionProcessor.php). My guess is you have a wrapper function around the logger and you're calling it from Writer.php -- BUT
If you look at the code for IntrospectionProcessor.php you'll see a bit of code on lines 81 to 87 that decides how to format that stack trace, and it still has access to the stack. If you bump the $i values for $trace[$i - 1] / $trace[$i] up one (aka $trace[$i]/$trace[$i + 1] respectively) you can 'climb' the stack back to where you want.
It's important to note that the 'class' and 'function' parts of the trace need to be one level of the stack higher than the 'file' and 'line.'
On a personal (plz dont mod me bruhs) note, I'd like to see functionality to include a stack offset when throwing the log in. I know what function I want to blame if an error shoots out when I write the error_log('ut oh') but I might(will) forget that by the time the 'ut oh' comes.

Couchbase - creating design documents through API

I've been using Couchbase for a large project where we only consume data, but have no requrirement to actually write to the Couchbase cluster. I want to write some management tools and be able to create Design Documents and Views through the API and not the web console.
Creating Documents is not an issue at all, but whenever I use setDesignDoc() I get the following error message:
Fatal error: Uncaught exception 'CouchbaseLibcouchbaseException' with message 'Failed to store design doc: Invalid input/arguments' in ....
I can get the actual view data from the source with getDesignDoc() and use it for the creating that design document on the destination server like so:
$connandleDestination->setDesignDoc( "myDesignDoc", $connSource->getDesignDoc("myDesignDoc") );
And that's where I get the above error message.
I'm using the PHP SDK by the way with the latest version against Couchbase 2.5.1
Can you confirm if what you've given as your example is the exact code you're using?
$connandleDestination->setDesignDoc( "myDesignDoc", $connSource->getDesignDoc("myDesignDoc") );
What you've given would not work as, from the API docs, the syntax is as follows:
setDesignDoc(string $name, string $document) : bool
Hence, it would appear you are trying to set a new doc, myDesignDoc to be equal to the design doc myDesignDoc, which would either not exist, or have no effect (as setting something to equal itself causes no change - and creating a new design doc with the name of an existing one will simply overwrite it).
Did you instead mean to just use get()? get() would return a document (which would be valid in the setDesignDoc input, and that document could have the same name as the new design doc to be created.

Symfony2 won't load custom authentication provider, loads DaoAuthenticationProvider

This is a continuation of my last question.
Hi,
I'm implementing, in a Symfony2 application, a custom authentication provider in order to authenticate against the Wordnik REST API.
On application load, no matter what request path, this is the exception I get:
( ! ) Fatal error: Cannot access parent:: when current class scope has no parent in /[..]/WordRot/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php on line 43
You can see the full stacktrace here.
Second to last line in the trace reveals that it is loading the DaoAuthenticationProvider:
18 0.0217 1922792 Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider->__construct( ) ../appDevDebugProjectContainer.php:3071
But none of my configuration refers to that provider, or anything that extends it. My custom provider directly implements the AuthenticationProviderInterface.
So I assume that my configuration is wrong, and somewhere I need to be explicitly setting the WordnikProvider, but I'm not sure where! Research has not provided any clues to this issue.
Any help would be much appreciated!
Files
/app/config/config.yml
/app/config/security.yml
/src/WordRot/PlayBundle/Security/Authentication/Provider/WordnikProvider.php
/src/WordRot/PlayBundle/Security/Authentication/Token/WordnikUserToken.php
/src/WordRot/PlayBundle/Security/Firewall/WordnikListener.php
/src/WordRot/PlayBundle/DependencyInjection/Security/Factory/WordnikFactory.php
the line return $this->authenticationManager->authenticate(new WordnikUserToken($username, $password, $this->providerKey)); in the WordnikListener goes to
Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager (classes.php)
authenticate.
$this->providers are DaoAuthentificationProvider, WordnikProvider and AnonymousAuthentificationProvider.
From the DaoAuthentificationProvider it only uses the method supports($token):
return $token instanceof UsernamePasswordToken && $this->providerKey === $token->getProviderKey();
which returns false so next in line is WordnikProvider.
Oh..misread: the error is in the constructor:
parent::__construct($userChecker, $providerKey, $hideUserNotFoundExceptions); seems to fail. Running PHP 5.4.10 or so I DON'T have an error!!
Either rm -rf vendor and run composer install again or try using a different PHP version!!
A had to create something like this a week ago.
At the and, I created a custom user provider, where I simply call the api and with the response i create the user or not.
I would advise to read this:
http://symfony.com/doc/2.0/cookbook/security/custom_provider.html

Categories