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

Fix EZP-23499: Fatal error removing class with unexistant datatype. #1094

Merged

Conversation

joaoinacio
Copy link

JIRA: https://jira.ez.no/browse/EZP-23499

This prevents a PHP fatal error when removing a class (contentType) if a datatype has been removed.
Instead, it is logged to error.log

@efernandes
Copy link

It seems nice to me. If for some reason the developer has missing attributes, that's he's problem in the end. Imo, if he really wants to remove the class and leave some nonused content in the database, he should be able to.

@andrerom
Copy link
Contributor

+0,8 Ideally there should be some script or something to remove attributes of a certain type. if all code needs to be paranoid about data returned from db it ends up being lots of output checks.

@crevillo
Copy link
Contributor

+1

@@ -857,6 +857,14 @@ function removeAttributes( $removeAttributes = false, $version = false )
foreach ( $classAttributes as $classAttribute )
{
$dataType = $classAttribute->dataType();
if ( $dataType == null )
Copy link
Member

Choose a reason for hiding this comment

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

Here you're checking with "==" (type flexible), but above with "!==" (strict). I'd expect both to be strict, or both to be non-strict. Or, how about doing instanceof checks in both cases?

Copy link
Author

Choose a reason for hiding this comment

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

sounds good, thanks.
I'll update to a strict check for simplicity, because this (actually, eZDataType::create()) should always return either a datatype or null.

(Even considering the possibility of loading an instance of some other class, a PHP fatal error would be appropriate in that case, I believe :) )

@joaoinacio
Copy link
Author

@andrerom: I tend to agree, but wouldn't that be more of an improvement?
IMHO, one is not supposed to uninstall datatypes while there are defined classes using it;
this fix just avoids a fatal error in such situations.

@andrerom
Copy link
Contributor

yes it would be

if ( $dataType === null )
{
eZDebug::writeError(
"Skipping removal of class attribute for non-existant datatype " . $classAttribute->DataTypeString,
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: s/non-existant/non-existent

@glye
Copy link
Member

glye commented Oct 29, 2014

+1 (when @lolautruche's concerns are closed)

@joaoinacio
Copy link
Author

Updated, thanks for the feedback.

if ( $dataType === null )
{
eZDebug::writeError(
"Skipping removal of class attribute for non-existant datatype " . $attribute->DataTypeString,
Copy link
Contributor

Choose a reason for hiding this comment

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

s/non-existant/non-existent

@lolautruche
Copy link
Contributor

+1, but you still have 2 typos :-)

@joaoinacio
Copy link
Author

all done, thanks again.

joaoinacio pushed a commit that referenced this pull request Oct 30, 2014
Fix EZP-23499: Fatal error removing class with unexistant datatype.
@joaoinacio joaoinacio merged commit 26bee38 into ezsystems:master Oct 30, 2014
andrerom added a commit that referenced this pull request Nov 4, 2014
andrerom added a commit that referenced this pull request Dec 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants