Symfony website got broken once pushed in production - symfony-3.2

I'm developing a website using Symfony 3.2, and it worked perfectly well on my machine. It also worked perfectly well when I pushed it on our pre-production server. But then when I pushed it on our production server, it got broken.
The first problem I meet is this error, when trying to load a simple page using the News entity:
Error 500: Class 'Fidelise\SignUpBundle\Entity\News' does not exist
And yet that class definitely does exist.
The other problem is, when trying to log in to the website, I get this error:
500 - The request timed out.
Everything else works fine. Why would it start bugging when in production environment? I can also add some code if needed.
EDIT: here is the code of the call to the News class
/**
* Display the news page
*
* #return Response
*/
public function newsAction()
{
$repositoryNews = $this->getDoctrine()->getRepository('FideliseSignUpBundle:News');
$years = $repositoryNews->getYears();
$news = $repositoryNews->getAll();
return $this->render('#FOSUser/Security/news.html.twig', [
'years' => $years,
'news' => $news
]);
}

Related

How to move Laravel Events into subdirectories and still have them work when broadcasting?

I've moved my Laravel Events into subdirectories, and now my broadcasted messages are not being received. Pusher shows them ok, and if I move them out of the subdirectories then they work as expected, so I believe this is a namespacing issue, but I cannot figure out how to make it work.
The Event I'm focusing on is called TeamInvitationEvent and is located in the Events->Company->Memberships directory.
Here is my Listener:
public function getListeners()
{
$user_id = Auth::id();
return [
'refresh-navigation-top-menu' => '$refresh',
"echo-private:user.{$user_id},TeamInvitationEvent" => 'notifyInvitation',
"echo-private:user.{$user_id},TeamInvitationCancelledEvent" => 'notifyInvitationCancelled',
"echo-private:user.{$user_id},TeamInvitationAcceptedEvent" => 'notifyInvitationAccepted',
"echo-private:user.{$user_id},TeamMemberRemovedEvent" => 'notifyMemberRemoved',
];
}
Here is a screenshot of my Pusher debug console, showing that the user is subscribed to the correct private channel, and that the API Message is being broadcast on that channel:
Here is a list of different ways I've tried to correct for the new namespace:
App.Events.Company.Memberships.TeamInvitationEvent
App\Events\Company\Memberships\TeamInvitationEvent
/App/Events/Company/Memberships/TeamInvitationEvent
.TeamInvitationEvent
There are no errors in the Laravel logs, or in the Pusher logs, and as I mentioned it works as expected if I don't move them into the subdirectory.
I'm running the following in my app:
Laravel v8
Livewire v2
Laravel Echo v1
Pusher
This was embarrassingly obvious, but here's what fixed it:
"echo-private:user.{$user_id},Company\Memberships\TeamInvitationEvent" => 'notifyInvitation'
The docs are very clear that "App\Events" is prepended to all events, so naturally I just needed to add the rest of the namespace to get it working. I looked back and I had actually tried this earlier, but I must have forgot to clear the cache. Big shout-out to #joshhanley on the Livewire Discord chat for getting me sorted on this.
Side Note: using broadcastAs() made this much cleaner:
public function broadcastAs()
{
return 'team.invitation';
}
But don't forget to add a '.' before this custom name in your view, like this:
"echo-private:user.{$user_id},.team.invitation" => 'notifyInvitation'

Error with date when upgrading to Laravel 7

I have successfully upgraded my Laravel instance to version 7. So far everything seems fine apart from the following error.
Argument 1 passed to Carbon\CarbonInterval::setLocalTranslator() must
implement interface Symfony\Component\Translation\TranslatorInterface,
instance of Carbon\Translator given, called in
/var/www/laravel/vendor/nesbot/carbon/src/Carbon/Traits/Difference.php
I have followed the upgrade documentation and have added the following to my models (but still having the same problem).
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
I have the same error here on the linux server but not under wampp...
it is being triggered by the following command : $hist->created_at->diffForHumans()
I have tried the new serialization as well in the model :
use DateTimeInterface;
/**
* Prepare a date for array / JSON serialization.
*
* #param \DateTimeInterface $date
* #return string
*/
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
Found it... The migration is not going well it seems.
SO modify the composer.json to migrate to laravel 7 and symfony 5.
Then remove vendor folder and reinstall everything
composer clearcache
composer install
then it worked again.
This worked for me on Laravel V7
Delete this file /vendor/symfony/translation/TranslatorInterface.php
Then run this command to refresh the mapping: composer dump-autoload

Accessing vuex modules data from within a plugin

I am moving some data from the vuex store into its own module. Most of it works great, but I'm running into an issue that I can't seem to fix.
I have a plugin that I add, and that plugin also needs access to the store.
So at the top of that plugin, we import the store:
import store from '../store/store';
great - further down that plugin, I'm accessing the data of the store in a method that I expose on the service:
hasPermission(permission) {
return (store.state.authorization.permissions.indexOf(permission) >= 0);
}
Please note authorization is now a seperate module, and is no longer part of the root state object.
now the funny thing is that the above will return an error telling me indexOf is not a function.
When I add the following, however:
hasPermission(permission) {
console.log('Validating permission ' + permission);
console.log(store.state);
return (store.state.authorization.permissions.indexOf(permission) >= 0);
}
I notice that (1) the output to console is what I expect it to be, and (2), I'm not getting the error, and my menu structure dynamically builds as expected...
so I'm a bit confused to say the least...
authorization.permissions is updated each time a user authenticates, logs out, or chooses another account to work on; in these cases we fetch updated permissions from the server and commit it to the store, so we can build our menu structure based on up-to-date permissions. Works pretty good, but I'm not sure I understand why this fails to be honest.
The plugin is created as follows in the install:
Vue.prototype.$security = new Vue(
...
methods: {
hasPermission: function(permission) {
...
}
}
...
);

JayData oData request with custom headers - ROUND 2

Few month back I was working on some Odata WCF project and I had some problems with parsing custom headers for token auth (apiKey).
At that time, being quite a noob (still am!), I posted this SO question: JayData oData request with custom headers
Today I am working on a new project with Jaydata Odata server and client library and this:
application.context.prepareRequest = function (r) {
r[0].headers['apikey'] = '123456';
};
was working fine till I had to do a MERGE request. I found out that somehow MERGE request was overriding my headers so I investigated further.
It appears at first that in the oDataProvider.js (~line 617) in the _saveRest method the headers are not inherited:
request = {
requestUri: this.providerConfiguration.oDataServiceHost + '/',
headers: {
MaxDataServiceVersion: this.providerConfiguration.maxDataServiceVersion
}
};
but a few lines later we get:
this.context.prepareRequest.call(this, requestData);
which "should" call my own prepareRequest, but doesnt... Instead it still points to:
//Line 11302 jaydata.js
prepareRequest: function () { },
which of course does... nothing! Funnilly enough, when you execute a simple GET the same code supposedly on the same context instance works and points to my prepareRequest override.
I can assert with enough confidence that somehow the context between GET/MERGE is not the same instance. I cant see, however, any place where the context instance is reassigned.
Has anyone got a clue?
PS: this is NOT a CORS issue. My OPTIONS is passing fine and manually feeding the headers in oDataProvider works.
More
I followed the lead on different context instances and found something interesting. calling EntitySet.save() ends up calling the EntityContext constructor. see trace:
$data.Class.define.constructor (jaydata.js:10015)
EntityContext (VM110762:7)
Service (VM110840:8)
storeToken.factory (jaydata.js:14166)
$data.Class.define._getContextPromise (jaydata.js:13725)
$data.Class.define._getStoreContext (jaydata.js:13700)
$data.Class.define._getStoreEntitySet (jaydata.js:13756)
$data.Class.define.EntityInstanceSave (jaydata.js:13837)
$data.Entity.$data.Class.define.save (jaydata.js:9774)
(anonymous function) (app.js:162) // My save()
That explains why I get two different instances...
Hack
Replacing the prepareRequest function direcly in the class definition works, but its ugly!
for now I can cope with this:
$data.EntityContext.prototype.prepareRequest = function (r) {
r[0].headers['apikey'] = '12345';
};
This works fine as long as you only need to talk to a single endpoint.
Final word based on my experience
As much as I like JayData, it is obvious that they created a monster and its getting out of their hands (poor forum, no community, half-documented,...).
I chose JD because I was lazy and wanted to keep working with my old WCF DataService. Switching to Web API seemed wrong or too much work for me.
Also as a .net dev I liked strong typing of my entities and the ability to work with a concrete model generated from the JD tools. However, in the end, I was adding confusion. Every time my server side model changed I had to fetch the new metadata and scaffold a new entityModel.
I ended up by switching to Web Api and migrated my data service layer to Breeze. And seriously! its a breeze to work with it!
The documentation is absolutely brilliant and here on S.O you can always count on Ward or Jay Tarband to reply with a very high amount of professionalism.
In the end I realize this should probably be more a wiki than a Question.....

Generate custom steps with behat

I try to write a custom step that's generate step
my code looks like :
/**
* #Then /^Check_raoul$/
*/
public function checkRaoul()
{
// grab the content ...
// get players ...
$to_return = array();
foreach ($players as $player) {
$player = $player->textContent;
if (preg_match('/^.*video=([^&]*)&.*$/', $player, $matches))
{
array_push($to_return, new Step\Then('I check the video of id "'.$matches[1].'"'));
}
}
return $to_return;
}
/**
* #Then /^I check the video of id "([^"]*)"$/
*/
public function iCheckTheVideoOfId($id)
{
// ...
}
works fine but when integrating to jenkins or un cli, if many executions of iCheckTheVideoOfId fail, I see just one error. I wish generate a number of steps equal to the number of iCheckTheVideoOfId calls
what I a doing wrong ?
We abandoned using Jenkins to do BDD checks due to the differences in how test feedback is presented and what Jenkins is capable of. We found that just running our suites locally and then a full check before pushing code to the repo produced better results and helped everyone get better at using the framework.
To answer your question directly I would suggest configuring your jenkins job to not fail when a test fails.
This can be accomplished by not outputting results at all. You can modify your command line options to not output failures at all and just log results to an output file. You could then run a script at the end to check for failures.