Skip to content

Commit

Permalink
Allow to enable debug in Status - Tools - Fetching section
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Jun 16, 2024
1 parent ce523c5 commit 5a290b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
22 changes: 21 additions & 1 deletion app/Console/Commands/FetchEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FetchEmails extends Command
*
* @var string
*/
protected $signature = 'freescout:fetch-emails {--days=3} {--unseen=1} {--identifier=dummy} {--mailboxes=0}';
protected $signature = 'freescout:fetch-emails {--days=3} {--unseen=1} {--debug=0} {--identifier=dummy} {--mailboxes=0}';

/**
* The console command description.
Expand Down Expand Up @@ -78,8 +78,13 @@ public function handle()
{
$now = time();
$successfully = true;
$debug = $this->option('debug');
Option::set('fetch_emails_last_run', $now);

if ($debug) {
\Config::set('imap.options.debug', true);
}

$this->line('['.date('Y-m-d H:i:s').'] Fetching '.($this->option('unseen') ? 'UNREAD' : 'ALL').' emails for the last '.$this->option('days').' days.');

if (Mailbox::getInProtocols() === Mailbox::$in_protocols) {
Expand Down Expand Up @@ -123,14 +128,29 @@ function ($mailboxId) {

$this->mailbox = $mailbox;
$this->extra_import = [];

$debug_log = '';

try {
if ($debug) {
ob_start();
}

$this->fetch($mailbox);

if ($debug) {
$debug_log = ob_get_contents();
ob_end_clean();
}
} catch (\Exception $e) {
$successfully = false;
$this->logError('Error: '.$e->getMessage().'; File: '.$e->getFile().' ('.$e->getLine().')').')';
}

if ($debug && $debug_log) {
$this->line($debug_log);
}

// Import emails sent to several mailboxes at once.
if (count($this->extra_import)) {
$this->line('['.date('Y-m-d H:i:s').'] Importing emails sent to several mailboxes at once: '.count($this->extra_import));
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/SystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public function toolsExecute(Request $request)
$params = [];
$params['--days'] = (int)$request->days;
$params['--unseen'] = (int)$request->unseen;
$params['--debug'] = (int)$request->debug;
\Artisan::call('freescout:fetch-emails', $params, $outputLog);
break;

Expand Down
5 changes: 4 additions & 1 deletion resources/views/system/tools.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
 
<input type="radio" value="1" name="unseen" @if ((int)old('unseen', 1)) checked @endif /> {{ __('Unread') }}
&nbsp;
<input type="radio" value="0" name="unseen" @if (!(int)old('unseen', 1)) checked @endif /> {{ __('All') }}
<input type="radio" value="0" name="unseen" @if (!(int)old('unseen', 1)) checked @endif /> {{ __('All') }}

&nbsp;
<input type="checkbox" value="1" name="debug" @if ((int)old('debug')) checked @endif /> {{ __('Debug') }}

</div>

Expand Down

0 comments on commit 5a290b3

Please sign in to comment.