Skip to content
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

dev/core#2369 - Change missing image fatal error to 404 #20447

Merged
merged 1 commit into from
May 31, 2021

Conversation

magnolia61
Copy link
Contributor

@magnolia61 magnolia61 commented May 29, 2021

Overview

A missing profile image results in a unnecessary fatal error

Before

Use a profile in order for users to be able to upload a profile image (image url field in contact table). Viewing the field while an image is missing results in a fatal error (user does not notice, it is only logged that way). Being a fatal error the report error extension would also notify us by email each time.

After

A missing image url field does not result in a fatal error being logged anymore. The regular 404 rules apply.

Technical Details

Removed the lines that would throw the error

Comments

The world will be a better place after this commit is merged

Issue can be found over here: https://lab.civicrm.org/dev/core/-/issues/2369

@civibot
Copy link

civibot bot commented May 29, 2021

(Standard links)

@civibot civibot bot added the master label May 29, 2021
@demeritcowboy
Copy link
Contributor

There was some talk in the ticket of making it a 404. Right now it has response code 200. If it is desired to make it 404, which seems reasonable, then in the else clause you could do CRM_Utils_System::sendResponse(new \GuzzleHttp\Psr7\Response(404));

@demeritcowboy demeritcowboy changed the title Remove fatal error for missing image dev/core#2369 - Remove fatal error for missing image May 30, 2021
@magnolia61
Copy link
Contributor Author

I had no clue how this would work @demeritcowboy Thanks for your suggestion.

When I search the core code I see these examples of throwing a 404
header("HTTP/1.0 404 Not Found");
and
CRM_Utils_System::setHttpHeader("Status", "404 Not Found");

Would the guzzle way be preferable you think?

@demeritcowboy
Copy link
Contributor

Good point. Looks like they all do the same thing. And it seems even when the header/code is missing either php or the browser figures it out and adds it if the other is present. So maybe header("HTTP/1.0 404 Not Found"); is best since then it's consistent with the rest of that file.

@magnolia61 magnolia61 force-pushed the missing_image_fatal_error branch from a8298a2 to 11c4684 Compare May 30, 2021 14:49
@magnolia61 magnolia61 changed the title dev/core#2369 - Remove fatal error for missing image dev/core#2369 - Change missing image fatal error to 404 May 30, 2021
@magnolia61
Copy link
Contributor Author

@demeritcowboy changed the PR to the header 404 version. Would you be able to test, review and approve?

@demeritcowboy
Copy link
Contributor

Ok cool. I don't think the return does anything since the function just returns right after anyway. But otherwise looks good and tests ok.

@demeritcowboy demeritcowboy added the merge ready PR will be merged after a few days if there are no objections label May 30, 2021
@eileenmcnaughton
Copy link
Contributor

tests have hung?

@eileenmcnaughton
Copy link
Contributor

test this please

@@ -55,7 +55,8 @@ public function run() {
CRM_Utils_System::civiExit();
}
else {
throw new CRM_Core_Exception(ts('Photo does not exist'));
header("HTTP/1.0 404 Not Found");
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say rather than doing a return here we should call CRM_Utils_System::civiExit() but this could also be a follow up to this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you suggest this a follow up? Or would more returns in civicrm code be candidates for CRM_Utils_System::civiExit() ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He might have just been politely trying to keep the PR from going on too long but if you want to update it now then you could pull the exit call out of the if, which funnily enough, makes it look more like it did 7 years ago.

    if ($cid) {
      $config = CRM_Core_Config::singleton();
      $fileExtension = strtolower(pathinfo($_GET['photo'], PATHINFO_EXTENSION));
      $this->download(
        $config->customFileUploadDir . $_GET['photo'],
        'image/' . ($fileExtension == 'jpg' ? 'jpeg' : $fileExtension),
        $this->ttl
      );
    }
    else {
      header("HTTP/1.0 404 Not Found");
    }
    CRM_Utils_System::civiExit();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled the exit outside of the if now. @demeritcowboy @seamuslee001 agree & approve?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you squash the commits?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Looks good - have updated label.

@demeritcowboy
Copy link
Contributor

jenkins retest this please (some kind of intermittent fail - rollover timing issue)

@yashodha
Copy link
Contributor

@seamuslee001
The tests are passing. It looks like ready to merge.
@magnolia61 Can you do the follow up PR as per suggestion?

@magnolia61
Copy link
Contributor Author

@yashodha I can also adjust this PR and change the
return
for
CRM_Utils_System::civiExit();
as @seamuslee001 suggests. Consensus on what would be best?

@magnolia61 magnolia61 force-pushed the missing_image_fatal_error branch from 11c4684 to 255993e Compare May 31, 2021 13:02
@magnolia61 magnolia61 force-pushed the missing_image_fatal_error branch from ae87b17 to 1a662f3 Compare May 31, 2021 13:17
@demeritcowboy demeritcowboy added merge on pass and removed merge ready PR will be merged after a few days if there are no objections labels May 31, 2021
@demeritcowboy demeritcowboy merged commit b89ccf7 into civicrm:master May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants