gordonbanderson /
freetextsearch
| 1 | <?php declare(strict_types = 1); |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Created by PhpStorm. |
||
| 5 | * User: gordon |
||
| 6 | * Date: 25/3/2561 |
||
| 7 | * Time: 17:01 น. |
||
| 8 | */ |
||
| 9 | |||
| 10 | namespace Suilven\FreeTextSearch\Task; |
||
| 11 | |||
| 12 | use League\CLImate\CLImate; |
||
| 13 | use SilverStripe\Control\Director; |
||
| 14 | use SilverStripe\Dev\BuildTask; |
||
| 15 | use SilverStripe\Security\Permission; |
||
| 16 | use SilverStripe\Security\Security; |
||
| 17 | use Suilven\FreeTextSearch\Helper\BulkIndexingHelper; |
||
| 18 | |||
| 19 | class ReindexTask extends BuildTask |
||
| 20 | { |
||
| 21 | |||
| 22 | protected $title = 'Reindex'; |
||
| 23 | |||
| 24 | protected $description = 'Reindex all dataobjects referred to in indexes'; |
||
| 25 | |||
| 26 | protected $enabled = true; |
||
| 27 | |||
| 28 | /** @var string */ |
||
| 29 | private static $segment = 'reindex'; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | /** |
||
| 35 | * Implement this method in the task subclass to |
||
| 36 | * execute via the TaskRunner |
||
| 37 | * |
||
| 38 | * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint |
||
| 39 | * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint |
||
| 40 | * @param \SilverStripe\Control\HTTPRequest $request |
||
| 41 | * @return \SilverStripe\Control\HTTPResponse|void |
||
| 42 | */ |
||
| 43 | public function run($request) |
||
| 44 | { |
||
| 45 | $climate = new CLImate(); |
||
| 46 | |||
| 47 | // check this script is being run by admin |
||
| 48 | // @phpstan-ignore-next-line |
||
| 49 | $canAccess = (Director::isDev() || Director::is_cli() || Permission::check("ADMIN")); |
||
| 50 | |||
| 51 | // for testing purposes |
||
| 52 | $fail = $request->getVar('fail'); |
||
| 53 | if (!\is_null($fail)) { |
||
| 54 | $canAccess = false; |
||
| 55 | } |
||
| 56 | |||
| 57 | if (!$canAccess) { |
||
| 58 | return Security::permissionFailure(null, 'Permission denied'); |
||
|
0 ignored issues
–
show
The expression
return SilverStripe\Secu...l, 'Permission denied') returns the type SilverStripe\Control\HTTPResponse which is incompatible with the return type mandated by SilverStripe\Dev\BuildTask::run() of void.
In the issue above, the returned value is violating the contract defined by the mentioned interface. Let's take a look at an example: interface HasName {
/** @return string */
public function getName();
}
class Name {
public $name;
}
class User implements HasName {
/** @return string|Name */
public function getName() {
return new Name('foo'); // This is a violation of the ``HasName`` interface
// which only allows a string value to be returned.
}
}
Loading history...
|
|||
| 59 | } |
||
| 60 | |||
| 61 | |||
| 62 | /** @var string $indexName */ |
||
| 63 | $indexName = $request->getVar('index'); |
||
| 64 | |||
| 65 | $helper = new BulkIndexingHelper(); |
||
| 66 | $helper->bulkIndex($indexName, false, $climate); |
||
| 67 | } |
||
| 68 | } |
||
| 69 |