project.module produces various PHP Notices with E_ALL on. These are all due to variables, array keys or object fields which may not exist when used.

This patch fixes those that I spotted, by changing to equivalent behaviour without Notices.

Examples:
1. Additional

  $output = '';

in project_page_overview(), that uses $output .= ... later.

2.

  if ($_POST['edit']['rid']) {

changed to

  if (!empty($_POST['edit']['rid'])) {

3.

    if ($project->release_count > 1) {

changed to

    if (isset($project->release_count) && $project->release_count > 1) {

4.

    if (module_invoke($module, 'project_sort_methods', 'group by date', $sort_method) && $date = _project_date($project->changed)) {

changed to

+    if (isset($module) && module_invoke($module, 'project_sort_methods', 'group by date', $sort_method) 
         && $date = _project_date($project->changed)) {

(Actually this indicates some other possible problem project_page_overview(), since presumably $module ought to exist at this point. So maybe this should be left as a bug to be fixed).

5.

  $output .= '<div class="project" id="project-overview">' . $projects . '</div>';

changed to

  $output .= '<div class="project" id="project-overview">' . (isset($projects) ? $projects : '') . '</div>';

although an alternative would be to show an alternative message if no projects were listed.

Best wishes,

Mark.

Comments

plumbley’s picture

Status: Active » Needs review

(Setting correct status)

drewish’s picture

Version: 4.7.x-1.0 » 5.x-1.x-dev
StatusFileSize
new3.24 KB

here's a re-roll for 5

hunmonk’s picture

Status: Needs review » Needs work

this is definitely wrong:

@@ -708,7 +709,7 @@
         'href' => "project/issues/$project->nid",
       );
     }
-    if (module_invoke($module, 'project_sort_methods', 'group by date', $sort_method) && $date = _project_date($project->changed)) {
+    if (isset($module) && module_invoke($module, 'project_sort_methods', 'group by date', $sort_method) && $date = _project_date($project->changed)) {
       $projects .= "<h3>$date</h3>";
     }
     $project->class = ($class == 'even') ? 'odd': 'even';

what are you doing that's resulting in $module not being set? that doesn't look possible to me. if it is, then we need to fix elsewhere.

plumbley’s picture

@hummonk - Sorry this is so long ago now that I don't remember what I did exactly. But I only ever started to try out Project, so this was probably either (1) browse of projects with no projects created yet, or (2) creation of first project. I think (2) is most likely, since most node add/edit forms ask for something about the (assumed to exist) item, but on create it doesn't exist yet so instead returns NULL node with PHP Notice.

A clean bare installation would be the most likely place to see this I think, since creating the first of a particular type can sometimes be a boundary case that isn't always catered for well.

hunmonk’s picture

the above mentioned weirdness w/ $module has been fixed elsewhere, so rip that out and roll a new patch against the latest code.

hunmonk’s picture

Status: Needs work » Needs review
StatusFileSize
new2.72 KB

this should do what we need. quick review would be nice.

dww’s picture

Status: Needs review » Reviewed & tested by the community

Visually looks fine and light testing on a local site reveals no problems. Didn't actually turn on E_ALL yet, so it's possible there are other warnings lurking, but this is certainly an improvement. Thanks.

drewish’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.71 KB

i turned on E_ALL and found a few more. we might as well get them all at once.

hunmonk’s picture

-    $version_form = drupal_get_form('project_release_version_filter_form', $version);
+    $version_form = drupal_get_form('project_release_version_filter_form');

something's wrong here. that form isn't built anywhere else that i can see, so what's the deal with function project_release_version_filter_form($version = NULL) if we're removing $version in the patch? do we need to get rid of $version as an arg, or correctly supply $version in function project_page_overview()?

hunmonk’s picture

Status: Needs review » Needs work
hunmonk’s picture

Version: 5.x-1.x-dev » 4.7.x-2.x-dev
Status: Needs work » Patch (to be ported)

reviewed, tested, committed to 5.x-1.x -- leaving to be ported if anybody cares to fix this in the older versions.

dww’s picture

Version: 4.7.x-2.x-dev » 5.x-1.x-dev
Status: Patch (to be ported) » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)