I have the following notification class:
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class ConfirmEmailNotification extends Notification implements ShouldQueue
{
use Queueable;
public function __construct()
{
//
}
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
$user = $notifiable;
$url = url('/register/confirm/'. $user->confirmation_token);
return (new MailMessage)
->subject('Confirm Email')
->markdown('emails.confirm', ['user' => $user, 'url' => $url]);
}
public function toArray($notifiable)
{
return [
//
];
}
}
In my controller I have the following:
$when = now()->addSeconds(30);
$user->notify((new ConfirmEmailNotification())->delay($when));
But nothing is getting added to the queue table - the emails is being fired instantly?
I configured the queue as follows.
In my env file:
QUEUE_DRIVER=database
In my config/queue.php I have renamed the table as follows:
'database' => [
'driver' => 'database',
'table' => 'queued_jobs',
'queue' => 'default',
'retry_after' => 90,
],
Run the following:
php artisan queue:table
php artisan migrate
php artisan queue:work
I've tried php artisan config:clear but no difference.
Any ideas chaps?
Fixed by restarting php artisan serve
In my case, i forgot to update the QUEUE_CONNECTION property in .env file.
After updating the QUEUE_CONNECTION to database it worked as intended.
Related
I am using Doctrine 2.5 with Slim 3. I got two Entity Managers Master and Slave.
In the Cli-Config.php file when I am creating the helpers and passing the entity Managers and their connections as below,
$helpers = new Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($defaultEntityManager->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($defaultEntityManager),
'db_customer' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($customerEntityManager->getConnection()),
'em_customer' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($customerEntityManager),
]);
return $helpers;
Now in the console when I try the command
php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create
the schema relating to $defaultEntityManager EntityManager is only getting created the schema relating to $customerEntityManager Entity Manager is not created.
Any idea/suggestions which I can try?
doctrine `s cli script expects 'em' to be defined in the HelperSet returned. That will be used to create the schema.
You can see it here
To solve this, one way is to create 2 directories like:
configA
configB
and place 2 different cli-config.php scripts in each:
$helpers = new Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($defaultEntityManager->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($defaultEntityManager),
]);
and
$helpers = new Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($customerEntityManager->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($customerEntityManager),
]);
Finally, run:
php ../vendor/doctrine/orm/bin/doctrine orm:schema-tool:create
from each directory
Creating own script
Alternatively, you could create your own script based on doctrine `s cli script, eg name it "doctrine.php":
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Helper\HelperSet;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
require_once __DIR__ . '/vendor/autoload.php';
$commands = [];
$helper1 = new Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($defaultEntityManager->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($defaultEntityManager),
]);
$helper2 = new Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($customerEntityManager->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($customerEntityManager),
]);
ConsoleRunner::run($helper1, $commands);
ConsoleRunner::run($helper2, $commands);
Place it on your project s root and run it as:
php doctrine.php orm:schema-tool:create
My solution is:
#!/usr/bin/env php
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
$commands = [];
$emList = [
$emFoo,
$emBar,
$emZoo
];
foreach ($emList as $em) {
$acpApp = ConsoleRunner::createApplication(ConsoleRunner::createHelperSet($em, $commands));
$acpApp->setAutoExit(false);
$acpApp->run();
}
I've made a web service using yii2 basic template I got a table called 'ely_usuario' when I call it with:
http://localhost/basic/web/index.php/ely-usuario/
it works fine and returns me all the rows in ely_usuario table
but when I try to get just one record, for example:
http://localhost/basic/web/index.php/ely-usuario/29
it doesn't work, show me a not found page, I've made the model class using gii
here's my Controller:
<?php
namespace app\controllers;
use yii\rest\ActiveController;
class ElyUsuarioController extends ActiveController
{
public $modelClass = 'app\models\ElyUsuario';
}
My configs:
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'ely-usuario'],
],
],
Another weird thing that you might noticed is that 'enableStrictParsing' is false, in the yii2 guide it says to be true but for me it only works with false
Thanks
You need to change the code in your configs.I hope you will get an idea from the following code.It works fine for me!
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:(ely-usuario)>/<action>/<id:\d+>' => '<controller>/<action>',
],
],
And in your controller please check your specific action.It must be coded like as:
public function actionTransactions($id=null){
if($id!=null){
//retrieve single row
}else{
//retrieve multiple rows
}
Also please check this link for reference:
Why RESTfull API request to view return 404 in Yii2?
I hope it helps!
I am using aws elastic service and indexed 650 000 data.
I need to add two new fields to the already indexed documents.
When I tried to call the updateByQuery function got the error, 'scripts of type [inline], operation [update] and lang [groovy] are disabled'.
I have fixed it by adding
script.engine.groovy.inline.aggs: on
script.engine.groovy.inline.update: on on elasticsearch.yml and it works perfectly on local .
How can I add this configuration on aws es ?
I am getting the same error when I am updating documents in aws elastic service.
Here is my code. I want to update all records ( where "device"= deviceVal) by adding new fields Site and Time.
var site = 'some value';
var deviceVal = '123';
var theScript = {
"inline": "ctx._source.Site = '"+ site + "';ctx._source.Time = '"+ new Date().getTime() + "'"
}
var match = {
"match": { "device": deviceVal }
}
client.updateByQuery({
index: 'my_index',
type:'txt',
"body": {
"query": match,
"script":theScript
}
}, function (error, response) {
// console.log("success")
console.log('error--',error)
console.log('response--',response)
});
Building on the other answer where we use logstash to reindex into an AWS ES cluster, you simply need to add one more transformation where # add other transformations here is mentioned.
In your case the input part needs to contain a query for the device:
input {
elasticsearch {
hosts => ["my-elasticsearch-domain.us-west-2.es.amazonaws.com:80"]
index => "my_index"
query => '{"query": {"match":{"device": "123"}}}'
docinfo => true
}
}
And the filter part would boil down to this, i.e. we rename the #timestamp field and add the Site field:
filter {
mutate {
remove_field => [ "#version" ]
rename => { "#timestamp" => "Time" }
add_field => { "Site" => "some value" }
}
}
consider the following:
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class HomeRouteTest extends TestCase
{
public function testVisitTheHomePage()
{
$response = $this->call('GET', '/');
$this->assertEquals(200, $response->status());
}
public function testVisitTheAboutPage()
{
$response = $this->call('GET', '/about');
$this->assertEquals(200, $response->status());
}
}
Is there away, not that I have seen documented >.>, to do something like:
$response = $this->call('GET', 'home.about');
$this->assertEquals(200, $response->status());
Or .... Is that how you do it?
The error I get is:
vagrant#scotchbox:/var/www$ phpunit
PHPUnit 4.8.21 by Sebastian Bergmann and contributors.
FF
Time: 3.41 seconds, Memory: 14.25Mb
There were 2 failures:
1) HomeRouteTest::testVisitTheHomePage
Failed asserting that 404 matches expected 200.
/var/www/tests/HomeRouteTest.php:12
2) HomeRouteTest::testVisitTheAboutPage
Failed asserting that 404 matches expected 200.
/var/www/tests/HomeRouteTest.php:19
FAILURES!
Tests: 2, Assertions: 2, Failures: 2.
This solution works for any Laravel 5 version to my knowledge. Especially Laravel 5.4+ unlike the other solution mentioned here.
If your named route has parameters, you can just do this:
$response = $this->get(route('users.show', [
'user' => 3,
]));
$response->assertStatus(200);
If your named route has no parameters then you can just do this:
$response = $this->get(route('users.index'));
$response->assertStatus(200);
Nice and simple.
This is a very late response, but I think what you're looking for is:
$this->route('GET', 'home.about');
$this->assertResponseOk(); // Checks that response status was 200
For routes with parameters, you can do this:
$this->route('GET', 'users.show', ['id' => 3]); // (goes to '/users/3')
I needed this to test some ghastly routes I'm working with, which look like this:
Route::resource(
'/accounts/{account_id}/users',
'AccountsController#users',
[
'parameters' => ['account_id'],
'names' => [
'create' => 'users.create',
'destroy' => 'users.destroy',
'edit' => 'users.edit',
'show ' => 'users.show',
'store' => 'users.store',
'update' => 'users.update',
]
]
);
To make sure that my routes and redirects went to the right page I did this:
/**
* #test
*/
public function users_index_route_loads_correct_page()
{
$account = Account::first();
$response = $this->route('get', 'users.index', ['account_id' => $account->id]);
$this->assertResponseOk()
->seePageIs('/accounts/' . $account->id . '/users');
}
To make sure I was using the right view file (we all make copy-paste errors, right?), I did this:
/**
* #test
*/
public function users_index_route_uses_expected_view()
{
$account = Account::first();
$response = $this->route('get', 'users.index', ['account_id' => $account->id]);
$view = $response->original; // returns View instance
$view_name = $view->getName();
$this->assertEquals($view_name, 'users.index');
}
If it weren't for the Structure feature in PHPStorm and the documentation from Laravel 4.2 that I stumbled over, I don't think I would have ever figured out how to test those routes. I hope this saves someone else a bit of time.
To be honest I don't see any reason to test names route. Named routes are rather for easier use inside application and you should rather test concrete url and not names route to make sure you are using correct url.
If you need to really test named route, I would create helper function for that with simple array:
protected function getNamedRoute($name)
{
$routes = [
'home.about' => '/about',
];
return $routes[$name];
}
and then in your test:
public function testVisitTheHomePage()
{
$response = $this->call('GET', $this->getNamedRoute('home.about'));
$this->assertEquals(200, $response->status());
}
The second thing is that you can make those tests a bit cleaner, you don't need to use:
$response = $this->call('GET', '/');
$this->assertEquals(200, $response->status());
you can use:
$this->visit('/')->seeStatusCode(200);
For me it's much more legible and you can write less code to achieve same.
I was following this tutorial for setting up Facebook PHP SDK 5.0 extension in my Yii 2.0 project. And it works as expected, but every time (in any of the controllers) I need to use some of the features from here this, I need to make an instance like this:
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.5',
// . . .
]);
and later use it:
// Send a GET request
$response = $fb->get('/me');
// Send a POST request
$response = $fb->post('/me/feed', ['message' => 'Foo message']);
// Send a DELETE request
$response = $fb->delete('/{node-id}');
but I'm not sure how practical is this, to make an instance of an object in every action/controller where I need to use it. I want to add this data as a general data in the config file. So I tried something like this:
'components' => [
.
.
'facebook' => [
'class' => 'Facebook\Facebook',
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.5'
],
.
.
and later in the actions I want to take this value like:
$fb = Yii::$app->facebook;
and after that do all the operations mentioned above. So I want to generalize the values in the config file like all other extensions, but I keep getting the error:
Facebook\Exceptions\FacebookSDKException
Required "app_id" key not supplied in config and could not find fallback environment variable "FACEBOOK_APP_ID"
Is it possible this to be entered in web config file, and with that, to avoid creating the object with same credentials before each Facebook call?
EDIT 1:
Reply to #machour response:
I followed your suggestion and It was still throwing the same error. Then I found it working as follows:
<?php
namespace your\namespace;
use Facebook\Facebook;
class MyFacebook extends Facebook {
public $app_id = '{app-id}';
public $app_secret = '{app-secret}';
public $default_graph_version = 'v2.5';
public function __construct()
{
parent::__construct([
'app_id' => $this->app_id,
'app_secret' => $this->app_secret,
'default_graph_version' => $this->default_graph_version
]);
}
}
And then:
'components' => [
.
.
'facebook' => [
'class' => 'your\namespace\MyFacebook'
]
At some point this is acceptable solution, since the redundancy is eliminated. The keys are not only at one place.
But do you have any idea how to transfer all the keys to the config file instead of the MyFacebook class?
The problem is that Facebook\Facebook doesn't implement $app_id, $app_secret and $default_graph_version as public properties, so your parameters are not taken in account when Yii builds the object declared in your component.
One way to fix that is to create your own class that extends Facebook, with those public properties, and to correctly call Facebook\Facebook constructor from it's own constructor. And then point your configuration to that new class instead :
<?php
namespace your\namespace;
use Facebook\Facebook;
class MyFacebook extends Facebook {
public $app_id;
public $app_secret;
public $default_graph_version;
public function __construct()
{
parent::__construct([
'app_id' => $this->app_id,
'app_secret' => $this->app_secret,
'default_graph_version' => $this->default_graph_version
]);
}
}
And then:
'components' => [
.
.
'facebook' => [
'class' => 'your\namespace\MyFacebook',
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.5'
],
That should do the trick.