During the past 12 hours our Drupal site has begun to display "Error 500" to some users and blank pages to others when attempting to view 2 courses that were being developed. Both of them will not allow you to access any node assigned to that course. This includes the course itself, book pages, and quizzes. I enabled error reporting and the pages are now displaying this for each node related to those courses:

Fatal error: __clone method called on non-object in /var/www/html/training/sites/all/modules/course/includes/CourseObjectNode.inc on line 118

I am not much of a programmer so this has been confusing to me trying to find similar issues. Thanks for any help.

CommentFileSizeAuthor
#11 fatal_error_clone-2631940-11.patch1.88 KBdjdevin

Comments

jcarkhuff created an issue. See original summary.

djdevin’s picture

Hi,

This is due to a change in the course API.

Can you please check the course outline and make sure that you do not have any course content (node-based) objects that are linked to a node that no longer exists?

We can work on adding an error message instead of the fatal error happening.

prattrob’s picture

Hi djdevin,

I am also working on this issue. Are you referring to the article here?

https://www.drupal.org/node/1534356

We are not able to access any of the course content objects for the affected courses. All the objects in the course display that same error...

djdevin’s picture

Hi,

I don't think it's related to that.

You can reproduce the issue pretty easily by

1) Create a course
2) Add a Poll object
3) Save the course outline
4) Delete the Poll content (not the course object)
5) Try and take the course

prattrob’s picture

Hi djdevin,

I followed the steps and was able to take the course. I didn't actually add any objects to the course besides the poll, and the poll didn't contain any information besides what is created by default. Is there something else I did not do correctly to replicate the issue?

Is there anything we can do to get more information on this error? We haven't changed anything with the Drupal installation since these courses were made so it seems odd they would just throw this error randomly after working fine.

jcarkhuff’s picture

Could the errors be related to nodes being added that have duplicate titles? Such as multiple quizzes being named 'Quiz'? This is the only thing I noticed about the nodes that were part of these courses.

djdevin’s picture

Nah I don't think so.

The error happens here

  public function setNode($node) {
    $this->node = clone $node;

But node is empty, so it dies. setNode is called when a course object is initializing. So if you were taking a course object that didn't have a node associated it would fatal out when it tries to load the object.

I think my steps reproduce it because we have some custom code doing things with the objects but let me see if I can get it to error on a clean D7.

The tests still come back okay so there has to be something with the course setup that causes this.

prattrob’s picture

Thanks that would be good if you can reproduce it. We can give you the core version we're on if you need it, along with any module versions.

We meant to post that line earlier. Our lines 117-120 look like this:

public function setNode($node) {
$this->node = clone $node;
$this->setInstanceId($this->node->nid);
}

We saw the code but like Josh mentioned we are not programmers so we are having a tough time figuring out.

sapiusenator’s picture

To fix this I made a TEMPORARY change to sites/all/modules/course/includes/CourseObjectNode.inc
After you make the change you shouldn't get an error or referenced content that you have deleted.
You can then go in there and remove the objects which you have referenced to the course
You will see errors when you try and do this but just save the course and you should be back where you started; after removing the references from the course that targeted deleted items. I would recommend changing your code back at that point to avoid any adverse effects.
117-120

public function setNode($node) {
$this->node = clone $node;
$this->setInstanceId($this->node->nid);
}

TO THIS

public function setNode($node) {
if(isset($node->nid)) {
$this->node = clone $node;
$this->setInstanceId($this->node->nid);
}else{
drupal_set_message('Missing course object.', 'status');
}
}

If you get the message, "Missing course object", you may have deleted a piece of course content which was being used as an object on the course without removing the object from the course itself; please review the objects in this course and delete any through object settings on outline and save outline.

I believe you can receive this message on most op requests for the course but if you goto outline you will see it there for sure and this is where you would work from to repair this issue.

sapiusenator’s picture

PLEASE also note if you had referenced a existing node when you created the object instead of supplying it through the course it appears that the object will require a substitute to delete it. Create a dummy piece of content you can reference and select it from the Content tab on "Course object settings" form. Under existing autocomplete field put your content title in there and select it then save. This should bring you back to the Course outline where you can save the course outline (you would be able to delete the object at that point also if you chose to do so).

djdevin’s picture

Version: 7.x-1.7 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.88 KB

Thanks for your feedback.

I made changes inside of CourseObjectNode, using the built-in object warnings so that a message is displayed in the course outline editor.

I also implemented access() for object nodes to prevent access to an object without a node.

This will prevent any fatals and give the course admin a prompt to fix the course.

Status: Needs review » Needs work

The last submitted patch, 11: fatal_error_clone-2631940-11.patch, failed testing.

jcarkhuff’s picture

Thank you all for the help, we're going to try applying this fix later today or early next week.

djdevin’s picture

If you could try it today that'd be great, it passed all the tests in d.o (and on our sites) so I could push it through.

prattrob’s picture

djdevin,

Thanks for all the help. We tried running the patch using git and got this output:

[root@system course]# git apply -v /root/drupal.patch
/root/drupal.patch:11: trailing whitespace.
if ($node = node_load($this->getInstanceId())) {
/root/drupal.patch:12: trailing whitespace.
$this->setNode($node);
/root/drupal.patch:13: trailing whitespace.
}
/root/drupal.patch:22: trailing whitespace.
if ($this->getNode()) {
/root/drupal.patch:29: trailing whitespace.
if ($this->getNode()) {
fatal: corrupt patch at line 65
[root@system course]#

djdevin’s picture

Drupal CI said it was okay :(

I usually do `patch -i file.patch -p1`

Unless you checked out Course via Git, the above is recommended

prattrob’s picture

I installed patch and tried your method, then received this message:

[root@system course]# patch -i /root/drupal.patch -p1
(Stripping trailing CRs from patch.)
patching file includes/CourseObjectNode.inc
patch unexpectedly ends in middle of line
Hunk #3 FAILED at 418.
1 out of 3 hunks FAILED -- saving rejects to file includes/CourseObjectNode.inc.rej
[root@system course]#

djdevin’s picture

Did you copy/paste the patch? Looks like the whitespace got messed up.

Try getting the file directly:

cd course
wget https://www.drupal.org/files/issues/fatal_error_clone-2631940-11.patch
patch -i fatal_error_clone-2631940-11.patch -p1

prattrob’s picture

I think it worked...

[root@system course]# patch -i /root/fatal_error_clone-2631940-11.patch -p 1
patching file includes/CourseObjectNode.inc
Reversed (or previously applied) patch detected! Assume -R? [n]
Apply anyway? [n] y
Hunk #1 FAILED at 10.
Hunk #2 FAILED at 68.
Hunk #3 succeeded at 418 (offset 1 line).
2 out of 3 hunks FAILED -- saving rejects to file includes/CourseObjectNode.inc. rej
[root@system course]# patch -i /root/fatal_error_clone-2631940-11.patch -p 1
patching file includes/CourseObjectNode.inc
Reversed (or previously applied) patch detected! Assume -R? [n] y
[root@system course]#

Wasn't sure which options to use since I've never patched Drupal before. I'll see if we can test it in a few.

prattrob’s picture

Actually it looks like the first time I ran it, the patch managed to edit some of the lines before it failed so I reversed it when I ran it again. We had a backup of the file so we restored it and reran the patch and it looks good now. We'll do some testing in the GUI shortly.

djdevin’s picture

Status: Needs work » Needs review

@prattrob any luck?

prattrob’s picture

We haven't gotten that error since we applied the patch as far as I know. Thanks for all your help!

djdevin’s picture

Status: Needs review » Fixed

  • djdevin committed 73eb8df on 7.x-1.x
    Issue #2631940 by djdevin: Fatal error: __clone method called on non-...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.