Skip to content

Laravel 9 style fixes #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function down()
}

/**
* @param bool $toFloat
* @param bool $toFloat
*/
private function migrateDurationValues(bool $toFloat = true)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Studio\Totem\Database\TotemMigration;

class AlterTaskResultsTableAddIndexOnCreatedAt extends TotemMigration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection(TOTEM_DATABASE_CONNECTION)
->table(TOTEM_TABLE_PREFIX.'task_results', function (Blueprint $table) {
$table->index('created_at');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::connection(TOTEM_DATABASE_CONNECTION)
->table(TOTEM_TABLE_PREFIX.'task_results', function (Blueprint $table) {
$table->dropIndex('created_at');
});
}
}
2 changes: 1 addition & 1 deletion resources/views/tasks/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</li>
<li>
<span class="uk-text-muted uk-float-right">Average Run Time</span>
<span class="uk-float-left">{{$task->results->count() > 0 ? number_format( $task->results->sum('duration') / (1000 * $task->results->count()) , 2) : '0'}} seconds</span>
<span class="uk-float-left">{{$task->results()->count() > 0 ? number_format( $task->results()->sum('duration') / (1000 * $task->results()->count()) , 2) : '0'}} seconds</span>
</li>
<li>
<span class="uk-text-muted uk-float-right">Next Run Schedule</span>
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/ListSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ListSchedule extends Command
/**
* Create a new command instance.
*
* @param Schedule $schedule
* @param Schedule $schedule
* @return void
*/
public function __construct(Schedule $schedule)
Expand Down
6 changes: 4 additions & 2 deletions src/Contracts/TaskInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,30 @@ public function find($id);

/**
* Returns all tasks.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findAll();

/**
* Returns all active tasks.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findAllActive();

/**
* Creates a new task with the given data.
*
* @param array $input
* @param array $input
* @return \Studio\Totem\Task
*/
public function store(array $input);

/**
* Updates the given task with the given data.
*
* @param array $input
* @param array $input
* @param \Studio\Totem\Task $task
* @return \Studio\Totem\Task
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Events/Creating.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Creating implements ShouldBroadcast
/**
* Create a new event instance.
*
* @param array $input
* @param array $input
*/
public function __construct(array $input)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Events/Deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Deleted extends Event
/**
* Create a new event instance.
*
* @param array $input
* @param Task $task
* @param array $input
* @param Task $task
*/
public function __construct()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Events/Executed.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Executed extends BroadcastingEvent
/**
* Executed constructor.
*
* @param Task $task
* @param string $started
* @param Task $task
* @param string $started
*/
public function __construct(Task $task, $started, $output)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Events/TaskEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TaskEvent extends Event
/**
* Constructor.
*
* @param Task $task
* @param Task $task
*/
public function __construct(Task $task)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Events/Updating.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Updating extends BroadcastingEvent
/**
* Create a new event instance.
*
* @param array $input
* @param Task $task
* @param array $input
* @param Task $task
*/
public function __construct(array $input, Task $task)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/ActiveTasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ActiveTasksController extends Controller
private $tasks;

/**
* @param TaskInterface $tasks
* @param TaskInterface $tasks
*/
public function __construct(TaskInterface $tasks)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/ExecuteTasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ExecuteTasksController extends Controller
private $tasks;

/**
* @param TaskInterface $tasks
* @param TaskInterface $tasks
*/
public function __construct(TaskInterface $tasks)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Controllers/ExportTasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ExportTasksController extends Controller

/**
* ExportTasksController constructor.
* @param TaskInterface $tasks
*
* @param TaskInterface $tasks
*/
public function __construct(TaskInterface $tasks)
{
Expand Down
7 changes: 5 additions & 2 deletions src/Http/Controllers/ImportTasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class ImportTasksController extends Controller

/**
* ImportTasksController constructor.
* @param TaskInterface $tasks
*
* @param TaskInterface $tasks
*/
public function __construct(TaskInterface $tasks)
{
Expand All @@ -25,7 +26,9 @@ public function __construct(TaskInterface $tasks)

/**
* Import tasks from a json file.
* @param \Studio\Totem\Http\Requests\ImportRequest $request
*
* @param \Studio\Totem\Http\Requests\ImportRequest $request
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function index(ImportRequest $request)
Expand Down
7 changes: 4 additions & 3 deletions src/Http/Controllers/TasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TasksController extends Controller
/**
* TasksController constructor.
*
* @param TaskInterface $tasks
* @param TaskInterface $tasks
*/
public function __construct(TaskInterface $tasks)
{
Expand All @@ -45,6 +45,7 @@ public function index()
->when(request('q'), function (Builder $query) {
$query->where('description', 'LIKE', '%'.request('q').'%');
})
->with('frequencies')
->paginate(20),
]);
}
Expand All @@ -71,7 +72,7 @@ public function create()
/**
* Store a newly created task in storage.
*
* @param TaskRequest $request
* @param TaskRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(TaskRequest $request)
Expand Down Expand Up @@ -119,7 +120,7 @@ public function edit(Task $task)
/**
* Update the specified task in storage.
*
* @param TaskRequest $request
* @param TaskRequest $request
* @param $task
* @return \Illuminate\Http\RedirectResponse
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Requests/ImportRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function messages()
*
* @param array|mixed $keys
* @return array
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function all($keys = null)
Expand All @@ -68,6 +69,7 @@ public function all($keys = null)
* Get the validated data from the request.
*
* @return array
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function validated()
Expand All @@ -84,7 +86,7 @@ public function validated()
/**
* * Handle a failed validation attempt.
*
* @param Validator $validator
* @param Validator $validator
*/
protected function failedValidation(Validator $validator)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/BuildCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function handle(Event $event)
/**
* Rebuild Cache.
*
* @param Event $event
* @param Event $event
*/
protected function build(Event $event)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/BustCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function handle(Event $event)
/**
* Clear Cache.
*
* @param Event $event
* @param Event $event
*/
protected function clear(Event $event)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Listeners/BustCacheImmediately.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BustCacheImmediately
/**
* Create the event listener.
*
* @param Container $app
* @param Container $app
*/
public function __construct(Container $app)
{
Expand All @@ -35,7 +35,7 @@ public function handle(Event $event)
/**
* Clear Cache.
*
* @param Event $event
* @param Event $event
*/
protected function clear(Event $event)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Listeners/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Listener implements ShouldQueue
/**
* Create the event listener.
*
* @param Container $app
* @param TaskInterface $tasks
* @param Container $app
* @param TaskInterface $tasks
*/
public function __construct(Container $app, TaskInterface $tasks)
{
Expand Down
10 changes: 5 additions & 5 deletions src/Repositories/EloquentTaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function builder(): Builder
/**
* Find a task by id.
*
* @param int|Task $id
* @param int|Task $id
* @return int|Task
*/
public function find($id)
Expand Down Expand Up @@ -87,7 +87,7 @@ public function findAllActive()
/**
* Create a new task.
*
* @param array $input
* @param array $input
* @return bool|Task
*/
public function store(array $input)
Expand All @@ -108,8 +108,8 @@ public function store(array $input)
/**
* Update the given task.
*
* @param array $input
* @param Task $task
* @param array $input
* @param Task $task
* @return bool|int|Task
*/
public function update(array $input, $task)
Expand All @@ -130,7 +130,7 @@ public function update(array $input, $task)
/**
* Delete the given task.
*
* @param int|Task $id
* @param int|Task $id
* @return bool
*/
public function destroy($id)
Expand Down
35 changes: 26 additions & 9 deletions src/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public function getUpcomingAttribute()
/**
* Convert a string of command arguments and options to an array.
*
* @param bool $console if true will convert arguments to non associative array
*
* @param bool $console if true will convert arguments to non associative array
* @return array
*/
public function compileParameters($console = false)
Expand Down Expand Up @@ -193,18 +192,36 @@ public function autoCleanup()
{
if ($this->auto_cleanup_num > 0) {
if ($this->auto_cleanup_type === 'results') {
$oldest_id = self::results()
$oldest_id = $this->results()
->orderBy('ran_at', 'desc')
->limit($this->auto_cleanup_num)
->get()
->min('id');
self::results()
->where('id', '<', $oldest_id)
->delete();
do {
$rowsToDelete = $this->results()
->where('id', '<', $oldest_id)
->limit(50)
->getQuery()
->select('id')
->pluck('id');

Result::query()
->whereIn('id', $rowsToDelete)
->delete();
} while ($rowsToDelete->count() > 0);
} else {
self::results()
->where('ran_at', '<', Carbon::now()->subDays($this->auto_cleanup_num - 1))
->delete();
do {
$rowsToDelete = $this->results()
->where('ran_at', '<', Carbon::now()->subDays($this->auto_cleanup_num - 1))
->limit(50)
->getQuery()
->select('id')
->pluck('id');

Result::query()
->whereIn('id', $rowsToDelete)
->delete();
} while ($rowsToDelete->count() > 0);
}
}
}
Expand Down
Loading