Answers.Body: <p>I took a look at the code for you, and I couldn't see a stand out problem. The bad news is that you need a developer to look at this, insert debug information (or run it in the debugger) and really figure out what's going on.</p>
  
  <p>Most helpful would be if you requested the logs from your SysAdmin, and then posted back when you have them. We need to figure the path of execution.</p>
  
  <p>Do you have custom extensions installed, and does it work if they are disabled?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-21T01:32:00.400Z
Answers.Text: The only extensions installed are: Related Permissions Module, CiviDiscount, and Mailchimp. I disabled all three, cleared the cache, and tried again - same result.
Answers.UserDisplayName: GRoston
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-17T22:50:16.623Z
Answers.LastActivityDate: 2016-03-17T22:50:16.623Z
Answers.UserDisplayName: JohnFF
Body: <p>For some reason, the Scheduled Job for Update Membership Statuses has not been working on my site for some time. When I run it, I get the following error message:</p>
  
  <p>Fatal error: Call to a member function delete() on a non-object in /home/neftempo/public_html/sites/all/modules/civicrm/CRM/Member/BAO/Membership.php on line 665</p>
  
  <p>I just updated the site from 4.6.8 to 4.7.4 and the problem was not resolved.</p>
  
  <p>Can someone please suggest how to resolve this problem - we need to update our membership statuses.</p>
  
  <p>p.s. The site is hosted on a shared server, so I do not have access to the actual log files - hopefully the above provides sufficient guidance.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-18T00:00:34.487Z
Comments.Text: are any types of Scheduled Jobs working?
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-21T01:26:31.797Z
Comments.Text: For some reason, cron has not been running. However, I did manually run the following scheduled jobs: CiviCRM Update Check, Clean-up Temporary Data and Files, Disable expired relationships, Process Inbound Emails, Send Scheduled Mailings, and Send Scheduled Reminders; and all ran successfully.
  
  I will try to insert some debug code and I will ask for copies of the log file.
Comments.UserDisplayName: GRoston
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-21T01:36:10.380Z
Comments.Text: Great. When you get them please update your question with all the information you‘ve uncovered!
  
  (I‘m pretty stoked to find out the cause of this!)
Comments.UserDisplayName: JohnFF
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-23T02:39:28.850Z
Comments.Text: I may have found something interesting: At line 658 of Membership.php, I inserted a fwrite of $membershipId. The first $membershipId belongs to a member whose membership arises because he belongs to an organization that is a member. The various values in array $membership that I could figure out seem to be correct. What is really strange is that the second time function deleteMembership is called, the same value of $membershipId is passed in! This would explain (I think) the error because array $membership is empty since this membership has already been deleted. Wonder why...
Comments.UserDisplayName: GRoston
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-23T02:41:23.067Z
Comments.Text: Just some more info: The membership of the organization with which the aforementioned member is associated has expired. The member does not have any special relationship with the organization - he is simply an employee. Based on these notes, is there anything specific for which you (all) think I should look?
Comments.UserDisplayName: GRoston
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-17T04:20:58.550Z
Comments.Text: So you are using 'inherited' membership based on "Employer of" for that membership type? that would explain why both the Org and the Individual has a membership, but the latter should be just inherited hence wouldn't be certain it would be set as a result of the Sch. Job rather than purely the inheritance
Comments.UserDisplayName: petednz - fuzion
Tags: <civimember><scheduled-job>
Title: Error when executing Update Membership Statuses Scheduled Job
ThreadText: # Error when executing Update Membership Statuses Scheduled Job
  
  (Asked by: username_0 on 2016-03-16)
  
  For some reason, the Scheduled Job for Update Membership Statuses has not been working on my site for some time. When I run it, I get the following error message:
  
  Fatal error: Call to a member function delete() on a non-object in /home/neftempo/public\_html/sites/all/modules/civicrm/CRM/Member/BAO/Membership.php on line 665
  
  I just updated the site from 4.6.8 to 4.7.4 and the problem was not resolved.
  
  Can someone please suggest how to resolve this problem - we need to update our membership statuses.
  
  p.s. The site is hosted on a shared server, so I do not have access to the actual log files - hopefully the above provides sufficient guidance.
  
  **Tags:** civimember, scheduled-job
  
  > **Comments:**
  > **username_1**: are any types of Scheduled Jobs working?  
  > **username_0**: For some reason, cron has not been running. However, I did manually run the following scheduled jobs: CiviCRM Update Check, Clean-up Temporary Data and Files, Disable expired relationships, Process Inbound Emails, Send Scheduled Mailings, and Send Scheduled Reminders; and all ran successfully.  I will try to insert some debug code and I will ask for copies of the log file.  
  > **username_2**: Great. When you get them please update your question with all the information you‘ve uncovered!  (I‘m pretty stoked to find out the cause of this!)  
  > **username_0**: I may have found something interesting: At line 658 of Membership.php, I inserted a fwrite of $membershipId. The first $membershipId belongs to a member whose membership arises because he belongs to an organization that is a member. The various values in array $membership that I could figure out seem to be correct. What is really strange is that the second time function deleteMembership is called, the same value of $membershipId is passed in! This would explain (I think) the error because array $membership is empty since this membership has already been deleted. Wonder why...  
  > **username_0**: Just some more info: The membership of the organization with which the aforementioned member is associated has expired. The member does not have any special relationship with the organization - he is simply an employee. Based on these notes, is there anything specific for which you (all) think I should look?  
  > **username_1**: So you are using 'inherited' membership based on "Employer of" for that membership type? that would explain why both the Org and the Individual has a membership, but the latter should be just inherited hence wouldn't be certain it would be set as a result of the Sch. Job rather than purely the inheritance  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-03-17. Score: 1
  
  I took a look at the code for you, and I couldn't see a stand out problem. The bad news is that you need a developer to look at this, insert debug information (or run it in the debugger) and really figure out what's going on.
  
  Most helpful would be if you requested the logs from your SysAdmin, and then posted back when you have them. We need to figure the path of execution.
  
  Do you have custom extensions installed, and does it work if they are disabled?
  
  > **Comments:**
  > **username_0**: The only extensions installed are: Related Permissions Module, CiviDiscount, and Mailchimp. I disabled all three, cleared the cache, and tried again - same result.  
  
  ---
  
  