Skip to content

Commit

Permalink
Deactivate auditing for import and increase max_execution_time
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Sep 12, 2024
1 parent cc10af0 commit 0a0b7a0
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/Models/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Models\Concerns\CustomAuditable;
use App\Models\Concerns\HasUuids;
use Database\Factories\ClientFactory;
use Illuminate\Database\Eloquent\Casts\Attribute;
Expand All @@ -12,7 +13,6 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

/**
Expand All @@ -29,7 +29,7 @@
*/
class Client extends Model implements AuditableContract
{
use Auditable;
use CustomAuditable;

/** @use HasFactory<ClientFactory> */
use HasFactory;
Expand Down
22 changes: 22 additions & 0 deletions app/Models/Concerns/CustomAuditable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Models\Concerns;

use OwenIt\Auditing\Auditable;

trait CustomAuditable
{
use Auditable;

/**
* @var array<string>|null
*/
protected ?array $auditEvents = null;

public function disableAuditing(): void
{
$this->auditEvents = [];
}
}
4 changes: 2 additions & 2 deletions app/Models/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace App\Models;

use App\Models\Concerns\CustomAuditable;
use App\Models\Concerns\HasUuids;
use Database\Factories\MemberFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
use Laravel\Jetstream\Membership as JetstreamMembership;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

/**
Expand All @@ -29,7 +29,7 @@
*/
class Member extends JetstreamMembership implements AuditableContract
{
use Auditable;
use CustomAuditable;

/** @use HasFactory<MemberFactory> */
use HasFactory;
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Models\Concerns\CustomAuditable;
use App\Models\Concerns\HasUuids;
use Database\Factories\OrganizationFactory;
use Illuminate\Database\Eloquent\Collection;
Expand All @@ -19,7 +20,6 @@
use Laravel\Jetstream\Events\TeamUpdated;
use Laravel\Jetstream\Jetstream;
use Laravel\Jetstream\Team as JetstreamTeam;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

/**
Expand All @@ -42,7 +42,7 @@
*/
class Organization extends JetstreamTeam implements AuditableContract
{
use Auditable;
use CustomAuditable;

/** @use HasFactory<OrganizationFactory> */
use HasFactory;
Expand Down
4 changes: 2 additions & 2 deletions app/Models/OrganizationInvitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace App\Models;

use App\Models\Concerns\CustomAuditable;
use App\Models\Concerns\HasUuids;
use Database\Factories\OrganizationInvitationFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
use Laravel\Jetstream\TeamInvitation as JetstreamTeamInvitation;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

/**
Expand All @@ -26,7 +26,7 @@
*/
class OrganizationInvitation extends JetstreamTeamInvitation implements AuditableContract
{
use Auditable;
use CustomAuditable;

/** @use HasFactory<OrganizationInvitationFactory> */
use HasFactory;
Expand Down
5 changes: 3 additions & 2 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Models\Concerns\CustomAuditable;
use App\Models\Concerns\HasUuids;
use Database\Factories\ProjectFactory;
use Illuminate\Database\Eloquent\Builder;
Expand All @@ -14,7 +15,6 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

/**
Expand All @@ -40,7 +40,7 @@
*/
class Project extends Model implements AuditableContract
{
use Auditable;
use CustomAuditable;

/** @use HasFactory<ProjectFactory> */
use HasFactory;
Expand All @@ -55,6 +55,7 @@ class Project extends Model implements AuditableContract
protected $casts = [
'name' => 'string',
'color' => 'string',
'archived_at' => 'datetime',
];

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Models/ProjectMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace App\Models;

use App\Models\Concerns\CustomAuditable;
use App\Models\Concerns\HasUuids;
use Database\Factories\ProjectMemberFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

/**
Expand All @@ -31,7 +31,7 @@
*/
class ProjectMember extends Model implements AuditableContract
{
use Auditable;
use CustomAuditable;

/** @use HasFactory<ProjectMemberFactory> */
use HasFactory;
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace App\Models;

use App\Models\Concerns\CustomAuditable;
use App\Models\Concerns\HasUuids;
use Database\Factories\TagFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

/**
Expand All @@ -25,7 +25,7 @@
*/
class Tag extends Model implements AuditableContract
{
use Auditable;
use CustomAuditable;

/** @use HasFactory<TagFactory> */
use HasFactory;
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Models\Concerns\CustomAuditable;
use App\Models\Concerns\HasUuids;
use Database\Factories\TaskFactory;
use Illuminate\Database\Eloquent\Builder;
Expand All @@ -14,7 +15,6 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

/**
Expand All @@ -34,7 +34,7 @@
*/
class Task extends Model implements AuditableContract
{
use Auditable;
use CustomAuditable;

/** @use HasFactory<TaskFactory> */
use HasFactory;
Expand Down
4 changes: 2 additions & 2 deletions app/Models/TimeEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Models\Concerns\CustomAuditable;
use App\Models\Concerns\HasUuids;
use App\Service\BillableRateService;
use Carbon\CarbonInterval;
Expand All @@ -14,7 +15,6 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
use Korridor\LaravelComputedAttributes\ComputedAttributes;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

/**
Expand Down Expand Up @@ -47,8 +47,8 @@
*/
class TimeEntry extends Model implements AuditableContract
{
use Auditable;
use ComputedAttributes;
use CustomAuditable;

/** @use HasFactory<TimeEntryFactory> */
use HasFactory;
Expand Down
4 changes: 2 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Models;

use App\Enums\Weekday;
use App\Models\Concerns\CustomAuditable;
use App\Models\Concerns\HasUuids;
use Database\Factories\UserFactory;
use Filament\Models\Contracts\FilamentUser;
Expand All @@ -25,7 +26,6 @@
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Jetstream\HasTeams;
use Laravel\Passport\HasApiTokens;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

/**
Expand Down Expand Up @@ -57,7 +57,7 @@
*/
class User extends Authenticatable implements AuditableContract, FilamentUser, MustVerifyEmail
{
use Auditable;
use CustomAuditable;
use HasApiTokens;

/** @use HasFactory<UserFactory> */
Expand Down
4 changes: 4 additions & 0 deletions app/Service/Import/ImportDatabaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ private function createEntity(array $identifierData, array $createValues, ?strin
throw new ImportException('Invalid data: '.implode(', ', $validator->errors()->all()));
}

/** @var TModel $model */
$model = new $this->model;
foreach ($data as $key => $value) {
$model->{$key} = $value;
}
if ($this->beforeSave !== null) {
($this->beforeSave)($model);
}
if (method_exists($model, 'disableAuditing')) {
$model->disableAuditing();
}
$model->save();

if ($this->afterCreate !== null) {
Expand Down
2 changes: 1 addition & 1 deletion config/octane.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
|
*/

'max_execution_time' => 30,
'max_execution_time' => 45,

/**
* Custom swoole config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function test_import_of_test_file_succeeds(): void
$queryLog = DB::getQueryLog();

// Assert
$this->assertCount(31, $queryLog);
$this->assertCount(23, $queryLog);
$testScenario = $this->checkTestScenarioAfterImportExcludingTimeEntries();
$this->checkTimeEntries($testScenario);
$this->assertSame(2, $report->timeEntriesCreated);
Expand Down

0 comments on commit 0a0b7a0

Please sign in to comment.