Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Fix MyBB build (#288)
Browse files Browse the repository at this point in the history
* Fix key generation

* Fix task to prevent running without connection to DB

* Fix Db connection check

* Remove unused class import
  • Loading branch information
Matslom authored and euantorano committed Jun 3, 2017
1 parent 54fb01b commit c8437bf
Show file tree
Hide file tree
Showing 5 changed files with 619 additions and 312 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
APP_KEY=SomeRandomStringWith32Characters

DB_HOST=localhost
DB_DATABASE=homestead
Expand Down
43 changes: 19 additions & 24 deletions app/Console/Commands/TaskMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace MyBB\Core\Console\Commands;

use Illuminate\Console\GeneratorCommand;
use Illuminate\Database\DatabaseManager;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -32,11 +31,6 @@ class TaskMakeCommand extends GeneratorCommand
*/
protected $type = 'MyBB Task';

/**
* @var DatabaseManager
*/
protected $dbManager;

/**
* @var TasksRepositoryInterface
*/
Expand All @@ -45,17 +39,14 @@ class TaskMakeCommand extends GeneratorCommand
/**
* TaskMakeCommand constructor.
* @param Filesystem $files
* @param DatabaseManager $dbManager
* @param TasksRepositoryInterface $tasksRepository
*/
public function __construct(
Filesystem $files,
DatabaseManager $dbManager,
TasksRepositoryInterface $tasksRepository
) {
parent::__construct($files);

$this->dbManager = $dbManager;
$this->tasksRepository = $tasksRepository;
}

Expand All @@ -68,21 +59,25 @@ public function fire()
{
$fileCreated = parent::fire();

if ($this->dbManager->connection() && $fileCreated !== false && !$this->option('no-database')) {
$task = $this->tasksRepository->createTask([
'namespace' => $this->getDefaultNamespace('MyBB\Core') . '\\' . $this->argument('name'),
'frequency' => $this->option('frequency'),
'name' => $this->option('name'),
'desc' => $this->option('description'),
'logging' => 1,
'enabled' => (int)$this->option('enabled'),
'last_run' => time(),
'next_run' => time(),
]);

if ($task) {
$this->info('Task successfully inserted to database');
try {
if ($fileCreated !== false && !$this->option('no-database')) {
$task = $this->tasksRepository->createTask([
'namespace' => $this->getDefaultNamespace('MyBB\Core') . '\\' . $this->argument('name'),
'frequency' => $this->option('frequency'),
'name' => $this->option('name'),
'desc' => $this->option('desc'),
'logging' => 1,
'enabled' => (int)$this->option('enabled'),
'last_run' => time(),
'next_run' => time(),
]);

if ($task) {
$this->info('Task successfully inserted to database');
}
}
} catch (\Exception $e) {
unset($e);
}
}

Expand Down Expand Up @@ -143,7 +138,7 @@ protected function getOptions()
return [
['command', null, InputOption::VALUE_OPTIONAL, 'The terminal command that should be assigned.', 'command'],
['frequency', 'f', InputOption::VALUE_OPTIONAL, 'Frequency of task execution.', '* * * * *'],
['name', 'n', InputOption::VALUE_OPTIONAL, 'Task display name language path.', 'admin::tasks.task'],
['name', null, InputOption::VALUE_OPTIONAL, 'Task display name language path.', 'admin::tasks.task'],
['desc', 'd', InputOption::VALUE_OPTIONAL, 'Task description language path.', 'admin::tasks.task'],
['enabled', 'e', InputOption::VALUE_OPTIONAL, 'Enable task?', 0],
['no-database', null, InputOption::VALUE_NONE, 'Do not insert task to database', null],
Expand Down
22 changes: 14 additions & 8 deletions app/Tasking/ScheduleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,22 @@ public function __construct(
* Run tasks from Command Line
*
* @param Schedule $schedule
* @return void
*/
public function runTasksFromCLI(Schedule $schedule)
{
$tasks = $this->tasksRepository->getEnabledTasks();
foreach ($tasks as $task) {
$schedule->call(function () use ($task) {
$this->runTask($task);
})->cron($task->frequency)
->name($task->namespace)
->withoutOverlapping();
// Check if we can grab tasks from database.
try {
$tasks = $this->tasksRepository->getEnabledTasks();
foreach ($tasks as $task) {
$schedule->call(function () use ($task) {
$this->runTask($task);
})->cron($task->frequency)
->name($task->namespace)
->withoutOverlapping();
}
} catch (\Exception $e) {
unset($e);
}
}

Expand All @@ -79,7 +85,7 @@ public function runTasksFromCLI(Schedule $schedule)
*
* @return bool
*/
public function runTasksFromWeb() : bool
public function runTasksFromWeb(): bool
{
if ($this->cache->has('tasks.fired')) {
// Nothing to do at this moment. Tasks were ran recently
Expand Down
Loading

0 comments on commit c8437bf

Please sign in to comment.