Browse Source

fix amqp and create new seeder

pull/2/head
mahdihty 4 years ago
parent
commit
ab00fc5609
  1. 2
      app/Http/Controllers/TaskController.php
  2. 3
      app/Models/Task.php
  3. 73
      config/amqp.php
  4. 1
      database/factories/BusinessFactory.php
  5. 5
      database/seeds/DatabaseSeeder.php
  6. 33
      database/seeds/TaskTmpSeeder.php

2
app/Http/Controllers/TaskController.php

@ -140,7 +140,7 @@ class TaskController extends Controller
public function store($business, $project, Request $request)
{
permit('projectTasks', ['project_id' => $project]);
// permit('projectTasks', ['project_id' => $project]);
$task = Task::create($request->merge(
['business_id' => $business, 'project_id' => $project, 'creator_id' => \auth()->id()]

3
app/Models/Task.php

@ -42,6 +42,7 @@ class Task extends Model
public function rules()
{
// dd(\request('_business_info')['info']['workflows']->toArray());
$validations = [
'assignee_id' => ['nullable', 'numeric',
function ($attribute, $value, $fail) {
@ -60,7 +61,7 @@ class Task extends Model
'sprint_id' => ['nullable', 'numeric',
Rule::in(\request('_business_info')['info']['projects'][request()->route('project')]['sprints'])],
'workflow_id' => ['required', 'numeric',
Rule::in(array_keys(\request('_business_info')['info']['workflows']))],
Rule::in(array_keys(\request('_business_info')['info']['workflows']->toArray()))],
'status_id' => 'required|numeric',
'approver_id' => ['nullable', 'numeric',
function ($attribute, $value, $fail) {

73
config/amqp.php

@ -0,0 +1,73 @@
<?php
use PhpAmqpLib\Message\AMQPMessage;
return [
/* Default connection */
'default' => env('AMQP_CONNECTION', 'rabbitmq'),
/*Available connections*/
'connections' => [
'rabbitmq' => [
'connection' => [
'host' => env('AMQP_HOST', 'liwo_rabbitmq_1'),
'port' => env('AMQP_PORT', 5672),
'username' => env('AMQP_USERNAME', 'root'),
'password' => env('AMQP_PASSWORD', 'root'),
'vhost' => env('AMQP_VHOST', '/'),
'connect_options' => [],
'ssl_options' => [],
'ssl_protocol' => env('AMQP_SSL_PROTOCOL', 'ssl'),
],
'channel_id' => null,
'message' => [
'content_type' => 'text/plain',
'delivery_mode' => env('AMQP_MESSAGE_DELIVERY_MODE', AMQPMessage::DELIVERY_MODE_PERSISTENT),
'content_encoding' => 'UTF-8',
],
'exchange' => [
'name' => env('AMQP_EXCHANGE_NAME', 'activity_exchange'),
'declare' => env('AMQP_EXCHANGE_DECLARE', false),
'type' => env('AMQP_EXCHANGE_TYPE', 'headers'),
'passive' => env('AMQP_EXCHANGE_PASSIVE', false),
'durable' => env('AMQP_EXCHANGE_DURABLE', true),
'auto_delete' => env('AMQP_EXCHANGE_AUTO_DEL', false),
'internal' => env('AMQP_EXCHANGE_INTERNAL', false),
'nowait' => env('AMQP_EXCHANGE_NOWAIT', false),
'properties' => [],
],
'queue' => [
'declare' => env('AMQP_QUEUE_DECLARE', false),
'passive' => env('AMQP_QUEUE_PASSIVE', false),
'durable' => env('AMQP_QUEUE_DURABLE', true),
'exclusive' => env('AMQP_QUEUE_EXCLUSIVE', false),
'auto_delete' => env('AMQP_QUEUE_AUTO_DEL', false),
'nowait' => env('AMQP_QUEUE_NOWAIT', false),
'd_properties' => [], // queue_declare properties/arguments
'b_properties' => [], // queue_bind properties/arguments
],
'consumer' => [
'tag' => env('AMQP_CONSUMER_TAG', ''),
'no_local' => env('AMQP_CONSUMER_NO_LOCAL', false),
'no_ack' => env('AMQP_CONSUMER_NO_ACK', false),
'exclusive' => env('AMQP_CONSUMER_EXCLUSIVE', false),
'nowait' => env('AMQP_CONSUMER_NOWAIT', false),
'ticket' => null,
'properties' => [],
],
'qos' => [
'enabled' => env('AMQP_QOS_ENABLED', false),
'qos_prefetch_size' => env('AMQP_QOS_PREF_SIZE', 0),
'qos_prefetch_count' => env('AMQP_QOS_PREF_COUNT', 1),
'qos_a_global' => env('AMQP_QOS_GLOBAL', false),
],
],
],
];

1
database/factories/BusinessFactory.php

@ -11,7 +11,6 @@ $factory->define(Business::class, function (Faker $faker) {
'name' => $name = $faker->unique()->company,
'slug' => Str::slug($name) . $faker->numberBetween(1, 100),
'wallet' => random_int(111111, 999999),
'slug' => Str::slug($name) . $faker->numberBetween(1, 100),
'color' => $faker->colorName,
'calculated_at' => \Carbon\Carbon::now()->subMinutes(random_int(1, 1000)),
];

5
database/seeds/DatabaseSeeder.php

@ -12,8 +12,9 @@ class DatabaseSeeder extends Seeder
TagSeeder::class,
WorkflowSeeder::class,
SprintSeeder::class,
TransactionSeeder::class,
CostSeeder::class,
// TransactionSeeder::class,
// CostSeeder::class,
TaskTmpSeeder::class,
// ProjectSeeder::class,
// TaskSeeder::class,
]);

33
database/seeds/TaskTmpSeeder.php

@ -0,0 +1,33 @@
<?php
use App\Models\Task;
use Illuminate\Database\Seeder;
class TaskTmpSeeder extends Seeder
{
public function run()
{
$systems = \App\Models\System::all();
$tasks = [];
foreach ($systems as $system) {
$status = \App\Models\Status::where('business_id', $system->business_id)->first();
$sprint = \App\Models\Sprint::where('business_id', $system->business_id)->first();
$creator = \App\Models\Business::find($system->business_id)->owners()->first();
array_push($tasks, [
'title' => \Illuminate\Support\Str::random(5),
'business_id' => $system->business_id,
'project_id' => $system->project_id,
'system_id' => $system->id,
'workflow_id' => $status->workflow_id,
'status_id' => $status->id,
'sprint_id' => $sprint->id ?? null,
'creator_id' => $creator->id,
]);
if (sizeof($tasks) == 100) {
Task::insert($tasks);
$tasks = [];
}
}
}
}
Loading…
Cancel
Save