Error in ResponseExeption while populating FOSElasticaBundle/Symfony2 - symfony

I am trying to get FOSElasticaBundle to work.
ElasticSearch Instance is running on localhost:9200 and responding.
I followed each step in the docs https://github.com/FriendsOfSymfony/FOSElasticaBundle/blob/master/Resources/doc/setup.md
but at the last step, I get this error in my console:
c:\xampp\htdocs\my\folder>php app/console fos:elastica:populate
Resetting app
Fatal error: Wrong parameters for Exception([string $exception [, long $code [,
Exception $previous = NULL]]]) in C:\xampp\htdocs\my\folder\vendor\rufli
n\elastica\lib\Elastica\Exception\ResponseException.php on line 34
[Symfony\Component\Debug\Exception\FatalErrorException]
Error: Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]])
fos:elastica:populate [--index[="..."]] [--type[="..."]] [--no-reset] [--offset="..."] [--sleep="..."] [--batch-size="..."] [--ignore-errors] [--no-overwrite-format]
It seems like there are 3 parameters mandatory for "__construct"-Function, but there are only 2 of them. I've simply tried to add "NULL"-parameter to get it work, but then another function throws an error.
public function __construct(Request $request, Response $response)
{
$this->_request = $request;
$this->_response = $response;
parent::__construct($response->getError());
}
Is this a common problem? How do I solve it?

This is because the ruflin/Elastica package is not compatible with elasticsearch 2.0 yet.
https://github.com/ruflin/Elastica/issues/946
An alternative for now (until ruflin/Elastica is 2.0 upgraded), is to use the latest 1.x version.
You can download it here: https://www.elastic.co/downloads/past-releases/elasticsearch-1-7-3
ES 1.7.3 + FosElasticaBundle (which uses ruflin/Elastica) works fine with Elasticsearch 1.7.3 version.

The reason for this issue is, that with elasticsearch 2.0 the structure of the response error changed (more details here: https://github.com/ruflin/Elastica/issues/946). Instead of a string before it is now a nested array. Elastica is currently not yet fully compatible with elasticsearch 2.0. As soon as a new release of Elastica is out which is compatible with Elasticsearch 2.0 it will probably mean that also foselastica bundle will have to be updated as these changes will break backward compatibility. Be also aware, that this is not the only backward compatibility breaking change.
To follow the progress of the upgrade, follow this issue: https://github.com/ruflin/Elastica/issues/946

Related

how to fix Botman error with conversation?

BotMan Version: 2.6
PHP Version: 8.1
Symfony Version : 5.4
Cache Driver: Symfony Cache
i'm using botman for telegram bot. everything is ok with botman just the conversation is not working
The question is asked, but when I answer, I see such an error.
An exception has been thrown during the rendering of a template ("Warning: is_file(): Unable to find the wrapper "closure" - did you forget to enable it when you configured PHP?").
Can someone help?
Tried to install php 8.2. Similarly
DriverManager::loadDriver(TelegramDriver::class);
$adapter = new FilesystemAdapter();
$botman = BotManFactory::create($this->config, new SymfonyCache($adapter));

Symfony 2.8 route annotation failing

Have looked through SO at various Symfony routing issues but no-one seems to have the same issue as this.
Yesterday, routing worked without issue.
Today I am getting errors regarding values being required for arguments with defaults set
This is an example route that is causing me a problem
#Route("/summary/{staffId}", name="task_instance_summary", requirements={"staffId":"\d+"},defaults={"staffId":"0"})
The method definition:
public function summaryAction(Request $request, $staffId)
and of course the error:
"Controller "PlanXL\TaskBundle\Controller\InstanceController::summaryAction()" requires that you provide a value for the "$staffId" argument (because there is no default value or because there is a non optional argument after this one).")
Debug output:
[router] Route "task_instance_summary"
Name task_instance_summary
Path /task/instance/summary/{staffId}
Path Regex #^/task/instance/summary(?:/(?P\d+))?$#s
Host ANY
Host Regex
Scheme ANY
Method ANY
Class Symfony\Component\Routing\Route
Defaults _controller: PlanXLTaskBundle:Instance:summary
staffId: 0
Requirements staffId: \d+
Options compiler_class: Symfony\Component\Routing\RouteCompiler
I have already cleared the cache (even though I am working on dev) but I can't see why I am getting an error. The router can obviously see the default value when I run the debug so why not when called through my application?
Try it;
public function summaryAction(Request $request, $staffId = 0)

Sudden syntax error after deployment

I have a working symfony project. I have it on a private bitbucked repository and locally the website works without an issue.
Today I tried to deploy the project onto an external server linuxpl.com.
Steps taken include:
Istalling composer
Adding the mysql database
Running git clone to get the data into a proper location
Running composer install on the folder to install everything and connect to the db
Cleared the cache
Set the project root as ....domain/project_name/web
However after completing all these steps, when running the website with regular server:run I'm getting this odd error:
Parse error: syntax error, unexpected '.' in /home/spirifer/domains/surowcewobiektywie.pl/konkurs/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1571
Not sure if this is of any importance but the mentioned code partion looks like this in my local files:
// Some objects throw exceptions when they have __call, and the method we try
// to call is not supported. If ignoreStrictCheck is true, we should return null.
try {
$ret = $object->$method(...$arguments);
} catch (BadMethodCallException $e) {
if ($call && ($ignoreStrictCheck || !$env->isStrictVariables())) {
return;
}
throw $e;
}
The local version does not differ from the one on the server.
My local machine has PHP 7.0.9 and the remove server has PHP 7.0.14
How could I fix this issue?
PHP 5.6 adds Variadic functions, with "...". However, Twig v1.x only required the use of PHP 5.2.7 or above.
If you didn't explicitly update to Twig 2.0, it's very possible you have used the 'death star' version constraint in the composer file - '*'. which allows uncontrolled version updates to the latest version. If this is the case, you will need to either update your version of PHP, or at least require just a previous version of Twig/twig, "^1.32" would be the latest in the version 1 series of Twig.

FOSRestBundle: PATCH methods not working (501 - Not implemented)

I'm using FOSUserBundle (the same problem on 0.12.0 and current dev-master) with Symfony 2.3.
I have problem with PATCH methods.
Simple example:
public function patchAction($slug)
{
[...]
return $view;
}
I see proper route was generated in php app/console router:debug:
api_patch_user PATCH ANY ANY /api/users/{slug}.{_format}
But when I am making request, I'm getting:
501 - Not implemented
When I change only method name to i.e. DELETE everything is working. So the problem is only with PATCH type requests.

Why does Symfony2 set the error_reporting?

I've been trying to remove the E_NOTICE and E_STRICT error levels to avoid this error:
Runtime Notice: Only variables should be passed by reference
I tried modifying php.ini but didn't work, error_reporting always is -1. Then I tried setting it dynamically in the current action, and worked fine. Then I also tried the same in the first line in app_dev.php and didn't work. Which means Symfony2 is setting it dynamically somewhere.
What should I do?
EDIT
For those who are not familiar with the error:
$user = $this->('security.context')->getToken()->getUser();
$first = reset($user->getRoles()); // error
$roles = $user->getRoles();
$first = reset($roles); // works fine
Whilst the notice is not 'retarded', this is a reasonable question in other contexts so: this is set in the Kernel instance, instantiated in app_dev.php (or app.php).
The second parameter to the construct is a boolean debug flag, and if true then error_reporting is set to -1 and display_errors to 1, otherwise default and 0 respectively.
$kernel = new AppKernel('dev', false);
symfony documentation
Hope this helps.
I got the same error in the following scenario i.e.
Scenario:
I lost the development environment for my existing LIVE project. But I got the whole code from GIT repo and then installed the symfony 2.4.2 (same version as on LIVE site) in my new development environment. Then I found that the web-application pages working on the LIVE site are broken in my new DEV environment.
Solution:
I spent quit a lot time to understand why the problem is then I found that i.e.
When I installed symfony 2.4.2 in my development environment using composer.phar then it created a new web/app_dev.php file in my development environment and it has the following entry to turn it off i.e.
Debug::enable();
Just comment the above line then the php notices will be off and then all the pages that were giving me notices are fixed.
I hope this will be helpful for someone having the same problem like me. Good Luck!
Cheers.
PS: But I will recommend to enable the above line in your new development projects so that you can see the PHP notices and then remove them during development.

Resources