This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Rebuilds all VirtualFieldIndexes |
||
4 | * |
||
5 | * @author Mark Guinn <[email protected]> |
||
6 | * @date 9.26.13 |
||
7 | * @package shop_search |
||
8 | * @subpackage tasks |
||
9 | */ |
||
10 | class BuildVFI extends BuildTask |
||
0 ignored issues
–
show
|
|||
11 | { |
||
12 | protected $title = 'Rebuild Virtual Field Indexes'; |
||
13 | protected $description = 'Rebuild all VFI fields on all tables and records.'; |
||
14 | |||
15 | static $recordsPerRequest = 200; |
||
0 ignored issues
–
show
The visibility should be declared for property
$recordsPerRequest .
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using class A {
var $property;
}
the property is implicitly global. To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2. ![]() |
|||
16 | |||
17 | function old_run($request) { |
||
0 ignored issues
–
show
|
|||
18 | $classes = VirtualFieldIndex::get_classes_with_vfi(); |
||
19 | ini_set('memory_limit', '1G'); |
||
20 | $start = (int)$request->requestVar('start'); |
||
21 | $n = $start; |
||
22 | |||
23 | // rebuild the indexes |
||
24 | foreach ($classes as $c) { |
||
25 | echo "Rebuilding $c..."; |
||
26 | $list = DataObject::get($c); |
||
27 | $count = $list->count(); |
||
28 | for ($i = $n; $i < $count; $i += 10) { |
||
29 | $chunk = $list->limit(10, $i); |
||
30 | if (Controller::curr() instanceof TaskRunner) echo "Processing VFI #$i...\n"; |
||
31 | foreach ($chunk as $rec) $rec->rebuildVFI(); |
||
32 | } |
||
33 | VirtualFieldIndex::build($c); |
||
34 | |||
35 | // echo "Republishing changed records..."; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
52% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
36 | // $list = DataObject::get($c); |
||
37 | // $count = $list->count(); |
||
38 | // for ($i = 0; $i < $count; $i += 10) { |
||
39 | // $chunk = $list->limit(10, $i); |
||
40 | // foreach ($chunk as $rec) { |
||
41 | // if ($rec->isPublished()) { |
||
42 | // $rec->publish('Stage', 'Live'); |
||
43 | // $rec->flushCache(); |
||
44 | // } |
||
45 | // } |
||
46 | // } |
||
47 | |||
48 | echo "<br>\n"; |
||
49 | } |
||
50 | |||
51 | echo "Task complete.\n\n"; |
||
52 | } |
||
53 | |||
54 | function run($request) { |
||
0 ignored issues
–
show
run uses the super-global variable $_GET which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
55 | increase_time_limit_to(); |
||
56 | $self = get_class($this); |
||
57 | $verbose = isset($_GET['verbose']); |
||
58 | |||
59 | if (isset($_GET['class']) && isset($_GET['id'])) { |
||
60 | $item = DataObject::get($_GET['class'])->byID($_GET['id']); |
||
61 | if (!$item || !$item->exists()) die('not found: ' . $_GET['id']); |
||
0 ignored issues
–
show
The method
run() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
62 | $item->rebuildVFI(); |
||
63 | echo "done"; |
||
64 | return; |
||
65 | } |
||
66 | |||
67 | if (isset($_GET['link'])) { |
||
68 | $item = SiteTree::get_by_link($_GET['link']); |
||
69 | if (!$item || !$item->exists()) die('not found: ' . $_GET['link']); |
||
0 ignored issues
–
show
The method
run() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
70 | $item->rebuildVFI(); |
||
71 | echo "done"; |
||
72 | return; |
||
73 | } |
||
74 | |||
75 | if (isset($_GET['start'])) { |
||
76 | $this->runFrom($_GET['class'], $_GET['start'], $_GET['field']); |
||
77 | } |
||
78 | else { |
||
79 | foreach(array('framework','sapphire') as $dirname) { |
||
80 | $script = sprintf("%s%s$dirname%scli-script.php", BASE_PATH, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); |
||
81 | if(file_exists($script)) { |
||
82 | break; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | $classes = VirtualFieldIndex::get_classes_with_vfi(); |
||
87 | foreach ($classes as $class) { |
||
88 | if (isset($_GET['class']) && $class != $_GET['class']) continue; |
||
89 | $singleton = singleton($class); |
||
90 | $query = $singleton->get($class); |
||
91 | $dtaQuery = $query->dataQuery(); |
||
92 | $sqlQuery = $dtaQuery->getFinalisedQuery(); |
||
93 | $singleton->extend('augmentSQL',$sqlQuery,$dtaQuery); |
||
94 | $total = $query->count(); |
||
95 | $startFrom = isset($_GET['startfrom']) ? $_GET['startfrom'] : 0; |
||
96 | $field = isset($_GET['field']) ? $_GET['field'] : ''; |
||
97 | |||
98 | echo "Class: $class, total: $total\n\n"; |
||
99 | |||
100 | for ($offset = $startFrom; $offset < $total; $offset += $this->stat('recordsPerRequest')) { |
||
101 | echo "$offset.."; |
||
102 | $cmd = "php $script dev/tasks/$self class=$class start=$offset field=$field"; |
||
0 ignored issues
–
show
The variable
$script does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
103 | if($verbose) echo "\n Running '$cmd'\n"; |
||
104 | $res = $verbose ? passthru($cmd) : `$cmd`; |
||
105 | if($verbose) echo " ".preg_replace('/\r\n|\n/', '$0 ', $res)."\n"; |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | } |
||
110 | |||
111 | protected function runFrom($class, $start, $field) { |
||
112 | $items = DataList::create($class)->limit($this->stat('recordsPerRequest'), $start); |
||
113 | foreach ($items as $item) { |
||
114 | $item->rebuildVFI($field); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | } |
||
119 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.