-
Notifications
You must be signed in to change notification settings - Fork 4
Modernise code #156
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
base: master
Are you sure you want to change the base?
Modernise code #156
Changes from all commits
8ff1fa2
d8f15e6
6f2502d
bde407b
bb04e72
3501f5d
f46986c
66fbe41
4107d39
00649d5
6b68f09
ae320fe
13752a2
22c5e0f
727c243
74ef976
982da60
900b332
f57cdee
25e8be9
6aa5979
74ee5e8
6184a28
06be561
4a4640d
5eaa2f8
f5be98e
a87df41
1922094
78db718
14c4766
02e88ae
efba683
cac8374
1cdb0e5
f676b4b
122d11c
3ddd2d6
58cb4d1
3c0a040
148d0db
18afec6
b25f9ad
af47f6e
747e6d3
86ed2a3
7ff25bc
d1c6901
143e27b
2adc875
351eb38
bfc8602
3ddf74b
119a88f
4a8479e
0f19674
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /.circleci/ export-ignore | ||
| /docker export-ignore | ||
| /test export-ignore | ||
| .editorconfig export-ignore | ||
| .env export-ignore | ||
| .php-cs-fixer* export-ignore | ||
| *.log export-ignore | ||
| docker-compose*.yml export-ignore | ||
| logo.png export-ignore | ||
| phpunit.xml export-ignore | ||
| phpstan*.neon export-ignore |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| parameters: | ||
| level: 5 | ||
| phpVersion: | ||
| min: 70400 # PHP 7.4 | ||
| max: 80419 # PHP 8.4.19 | ||
| tips: | ||
| treatPhpDocTypesAsCertain: false | ||
| ignoreErrors: | ||
| - '#Access to undefined constant MongoDB\\Driver\\ReadPreference\:\:RP_.*#' | ||
| - '#Call to an undefined method MongoDB\\Driver\\ReadPreference\:\:getMode\(\)#' | ||
| - identifier: missingType.iterableValue | ||
| reportUnmatched: false | ||
| - identifier: unset.possiblyHookedProperty | ||
| reportUnmatched: false | ||
| paths: | ||
| - src | ||
| - test | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| <?php | ||
|
|
||
| use Tripod\Config; | ||
| use Tripod\iTripodStat; | ||
| use Tripod\ITripodStat; | ||
| use Tripod\Mongo\Driver; | ||
| use Tripod\Timer; | ||
|
|
||
|
|
@@ -20,20 +20,23 @@ | |
| ] | ||
| ); | ||
|
|
||
| function showUsage($scriptName) | ||
| function showUsage(): void | ||
| { | ||
| $scriptName = basename(__FILE__); | ||
| $help = <<<END | ||
| {$scriptName} | ||
|
|
||
| Usage: | ||
|
|
||
| php {$scriptName} -c/--config path/to/tripod-config.json -s/--storename store-name [options] | ||
|
|
||
| Options: | ||
| -h --help This help | ||
| -c --config path to MongoTripodConfig configuration (required) | ||
| -s --storename Store to create views for (required) | ||
| -s --storename Store to create search documents for (required) | ||
| -d --spec Only create for specified search document specs | ||
| -i --id Resource ID to regenerate search documents for | ||
| -a --async Generate table rows via queue | ||
| -a --async Generate search documents via queue | ||
| -q --queue Queue name to place jobs on (defaults to configured TRIPOD_APPLY_QUEUE value) | ||
|
|
||
| --stat-loader Path to script to initialize a Stat object. Note, it *must* return an iTripodStat object! | ||
|
|
@@ -42,32 +45,27 @@ function showUsage($scriptName) | |
| echo $help; | ||
| } | ||
|
|
||
| if (empty($options) || isset($options['h']) || isset($options['help']) | ||
| if ( | ||
| $options === [] || $options === false || isset($options['h']) || isset($options['help']) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment: I am surprised that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is on Rector: https://getrector.com/rule-detail/disallowed-empty-rule-fixer-rector. Since PHP's From type safety standpoint this make more sense, since the definition of what "empty" means in PHP is quite loose... $ php -r 'var_dump(empty("0"));'
bool(true) |
||
| || (!isset($options['c']) && !isset($options['config'])) | ||
| || (!isset($options['s']) && !isset($options['storename'])) | ||
| ) { | ||
| showUsage(); | ||
|
|
||
| exit; | ||
| } | ||
|
|
||
| $configLocation = $options['c'] ?? $options['config']; | ||
|
|
||
| require_once dirname(__FILE__, 3) . '/src/tripod.inc.php'; | ||
|
|
||
| /** | ||
| * @param string|null $id | ||
| * @param string|null $specId | ||
| * @param string|null $storeName | ||
| * @param iTripodStat|null $stat | ||
| * @param string|null $queue | ||
| */ | ||
| function generateSearchDocuments($id, $specId, $storeName, $stat = null, $queue = null) | ||
| function generateSearchDocuments(?string $id, string $specId, string $storeName, ?ITripodStat $stat = null, ?string $queue = null): void | ||
| { | ||
| $spec = Config::getInstance()->getSearchDocumentSpecification($storeName, $specId); | ||
| if (array_key_exists('from', $spec)) { | ||
| Config::getInstance()->setMongoCursorTimeout(-1); | ||
|
|
||
| echo "Generating {$specId}"; | ||
| echo 'Generating ' . $specId; | ||
| $tripod = new Driver($spec['from'], $storeName, ['stat' => $stat]); | ||
| $search = $tripod->getSearchIndexer(); | ||
| if ($id) { | ||
|
|
@@ -85,31 +83,13 @@ function generateSearchDocuments($id, $specId, $storeName, $stat = null, $queue | |
|
|
||
| Config::setConfig(json_decode(file_get_contents($configLocation), true)); | ||
|
|
||
| if (isset($options['s']) || isset($options['storename'])) { | ||
| $storeName = $options['s'] ?? $options['storename']; | ||
| } else { | ||
| $storeName = null; | ||
| } | ||
|
|
||
| if (isset($options['d']) || isset($options['spec'])) { | ||
| $specId = isset($options['d']) ? $options['t'] : $options['spec']; | ||
| } else { | ||
| $specId = null; | ||
| } | ||
|
|
||
| if (isset($options['i']) || isset($options['id'])) { | ||
| $id = $options['i'] ?? $options['id']; | ||
| } else { | ||
| $id = null; | ||
| } | ||
| $storeName = $options['s'] ?? $options['storename'] ?? null; | ||
| $specId = $options['d'] ?? $options['spec'] ?? null; | ||
| $id = $options['i'] ?? $options['id'] ?? null; | ||
|
|
||
| $queue = null; | ||
| if (isset($options['a']) || isset($options['async'])) { | ||
| if (isset($options['q']) || isset($options['queue'])) { | ||
| $queue = $options['queue']; | ||
| } else { | ||
| $queue = Config::getInstance()->getApplyQueueName(); | ||
| } | ||
| $queue = $options['q'] ?? $options['queue'] ?? Config::getInstance()->getApplyQueueName(); | ||
| } | ||
|
|
||
| $stat = null; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woop woop