Skip to content

Commit

Permalink
fix(backend): add a few options to the messages_list worker allowing …
Browse files Browse the repository at this point in the history
…to define all required constants and have all required scripts imported (#1457)
  • Loading branch information
mercihabam authored Feb 24, 2025
1 parent 8aa4f07 commit 83ae17d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,4 @@ FANCY_LOGIN=false
WIN_CACERT_DIR=

JS_EXCLUDE_DEPS=
WORKER_CUSTOM_IMPORTS=
15 changes: 14 additions & 1 deletion modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,20 @@ function getCombinedMessagesLists($sources, $context, $search) {
$promises = array_map(function ($dataSource, $index) use ($context, $search) {
return function () use ($dataSource, $context, $search, $index) {
return new Promise(function ($resolve, $reject) use ($dataSource, $context, $search, $index) {
$process = new Process('php ' . __DIR__ . '/workers/messages_list.php');
$cmd = 'php ' . __DIR__ . '/workers/messages_list.php';
if (APP_PATH) {
$cmd .= ' -p ' . APP_PATH;
}
if (env('WORKER_CUSTOM_IMPORTS')) {
$cmd .= ' -i ' . env('WORKER_CUSTOM_IMPORTS');
}
if (CACHE_ID) {
$cmd .= ' -c ' . CACHE_ID;
}
if (SITE_ID) {
$cmd .= ' -s ' . SITE_ID;
}
$process = new Process($cmd);
$process->start(Loop::get());
$process->stdin->write(json_encode([
'index' => $index,
Expand Down
28 changes: 22 additions & 6 deletions modules/imap/workers/messages_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,31 @@
die("Must be run from the command line\n");
}

const APP_PATH = '';
$options = getopt('p:i:c:s:', ['app_path:', 'imports:', 'cache_id:', 'site_id:']);

require 'lib/framework.php';
$appPath = $options['app_path'] ?? $options['p'] ?? '';
$imports = $options['imports'] ?? $options['i'] ?? '';
$cacheId = $options['cache_id'] ?? $options['c'] ?? '';
$siteId = $options['site_id'] ?? $options['s'] ?? '';

require 'modules/core/message_functions.php';
require 'modules/core/message_list_functions.php';
define('APP_PATH', $appPath);
define('CACHE_ID', $cacheId);
define('SITE_ID', $siteId);

require 'modules/imap/hm-imap.php';
require 'modules/core/hm-mailbox.php';
require $appPath . 'lib/framework.php';

require $appPath . 'modules/core/message_functions.php';
require $appPath . 'modules/core/message_list_functions.php';

require $appPath . 'modules/imap/hm-imap.php';
require $appPath . 'modules/core/hm-mailbox.php';

if ($imports) {
$imports = explode(',', $imports);
foreach ($imports as $import) {
require $import;
}
}

$input = trim(fgets(STDIN));
$data = json_decode($input, true);
Expand Down

0 comments on commit 83ae17d

Please sign in to comment.