I just installed the latest dev on my local testsite. (wamp server)
When I add another sitemap I get the following error:
recoverable fatal error: Argument 1 passed to xmlsitemap_sitemap_save() must be an instance of stdClass, array given, called in C:\wamp\www\drupal\sites\all\modules\xmlsitemap\xmlsitemap.admin.inc on line 238 and defined in C:\wamp\www\drupal\sites\all\modules\xmlsitemap\xmlsitemap.module on line 381.
recoverable fatal error: Argument 1 passed to xmlsitemap_sitemap_get_context_hash() must be an array, null given, called in C:\wamp\www\drupal\sites\all\modules\xmlsitemap\xmlsitemap.module on line 386 and defined in C:\wamp\www\drupal\sites\all\modules\xmlsitemap\xmlsitemap.module on line 472.
warning: asort() expects parameter 1 to be array, null given in C:\wamp\www\drupal\sites\all\modules\xmlsitemap\xmlsitemap.module on line 473.
warning: Attempt to assign property of non-object in C:\wamp\www\drupal\sites\all\modules\xmlsitemap\xmlsitemap.module on line 386.
warning: array_fill() [function.array-fill]: Number of elements must be positive in C:\wamp\www\drupal\includes\database.inc on line 253.
warning: implode() [function.implode]: Invalid arguments passed in C:\wamp\www\drupal\includes\database.inc on line 253.
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 query: SELECT * FROM xmlsitemap_sitemap WHERE smid IN () in C:\wamp\www\drupal\sites\all\modules\xmlsitemap\xmlsitemap.module on line 343.

Also the default sitemap (the one that is automatically created after installing the module) is deleted.
Now there are no XML sitemaps available.
Then I click "Add new XML sitemap".
Then I choose the desired language. (I have a multilingual site)
I choose English.

Then I get the following error:
Fatal error: Cannot use object of type stdClass as array in C:\wamp\www\drupal\sites\all\modules\xmlsitemap\xmlsitemap.admin.inc on line 232

I enabled following XML sitemap modules:
XML sitemap
XML sitemap internationalization
XML sitemap node

I uninstalled and reinstalled the module(s). Still the same issue.

Comments

Dave Reid’s picture

Status: Active » Postponed (maintainer needs more info)

Make sure to re-download the latest 6.x-2.x-dev release. This should have been fixed already.

digi24’s picture

I have just installed current domain_xmlsitemap and updated to latest xmlsitemap 6.2-dev and I am experiencing exactly the same problem.

Dave Reid’s picture

Make sure you are using the *same* versions of xmlsitemap and domain_xmlsitemap. Use the beta1 release or the latest dev release, but don't mix them up.

tomsm’s picture

Status: Fixed » Postponed (maintainer needs more info)

I have redownloaded the latest dev (2010-Sep-24). I do not use domain_xmlsitemap. Still the same errors.

Core & modules that I use:
drupal 6.19
Internationalization 6.x-1.7
Internationalization views 6.x-3.x-dev (2010-Jul-21)
Views 6.x-3.x-dev (2010-Sep-15)
CCK 6.x-3.x-dev (2010-Aug-26)

I noticed something about the XML sitemap internationalization: When I installed the module the default sitemap has its language set to Default. This sitemap includes items in all languages.
When I try to add a sitemap, I can only select a specific language (in my case: English, French and Dutch), not default. I thought that the default language is the one in which you installed drupal, in my case English. So a sitemap that contains links in all languages should have as language "All" and not "Default". I do not think that this has anything to do with this issue, so maybe I should reopen a new one for this?

digi24’s picture

To reproduce the problem:
1. Unistalled everything.
2. Installed xmlsitemap module and domain_xmlsitemap (both latest dev)
-> Example sitemap ist installed.
3. Tried deleting sitemap -> no buttons show up on confirm page, no deleting possible
4. Changed the default path for sitemap cache
default sitemap still at old path
5. tried adding new sitemap for same domain
sitemap is deleted, it is not possible to add a new sitemap "Cannot use object of type stdClass as array in ..."

Dave Reid’s picture

Status: Postponed (maintainer needs more info) » Fixed

Thanks for the report back. I double checked and think I found the bug you were encountering. I have committed fixes to CVS on both D7 and D6:
http://drupal.org/cvs?commit=427026
http://drupal.org/cvs?commit=427028

digi24’s picture

Status: Postponed (maintainer needs more info) » Active

Thanks Dave, the problem with the delete buttons is fixed and there is also a warning about deleting the last sitemap.

However, given the setup without any sitemaps, I still cannot create new ones. The strange thing is inthe following function, where I added a var_dump():


function xmlsitemap_sitemap_save(stdClass &$sitemap) {
  xmlsitemap_load_all_includes();

  // Make sure context is sorted before saving the hash.
  $smid_old = isset($sitemap->smid) ? $sitemap->smid : NULL;
  $sitemap->smid = xmlsitemap_sitemap_get_context_hash($sitemap->context);
  var_dump($sitemap);
...

somehow the variable is still an array and the smid is not set:

array
  'smid' => null
  'context' => 
    array
      'domain' => string '4' (length=1)
  'op' => string ...

So I tried changing it to:


function xmlsitemap_sitemap_save(stdClass &$sitemap) {
  if(!is_object($sitemap)){
    $sitemap = (object) $sitemap;
  }
  xmlsitemap_load_all_includes();
...

and now the smid gets set correctly, however now the FAPI goes crazy: Fatal error: Cannot use object of type stdClass as array in /var/www/live/includes/form.inc on line 421

digi24’s picture

Status: Active » Needs review

Still not sure about the typecasting (probably wrong, could as well omit the back reference), but found the problem in the if clause:


Index: xmlsitemap.admin.inc
===================================================================
--- xmlsitemap.admin.inc        (revision 1844)
+++ xmlsitemap.admin.inc        (working copy)
@@ -235,7 +235,8 @@
 }

 function xmlsitemap_sitemap_edit_form_submit($form, &$form_state) {
-  xmlsitemap_sitemap_save($form_state['values']);
+  $values = (object) $form_state['values'];
+  xmlsitemap_sitemap_save($values);
   drupal_set_message(t('The sitemap has been saved.'));
   $form_state['redirect'] = 'admin/settings/xmlsitemap';
   // @todo If context was changed, needs to be regenerated.
Index: xmlsitemap.module
===================================================================
--- xmlsitemap.module   (revision 1844)
+++ xmlsitemap.module   (working copy)
@@ -400,7 +400,7 @@
     variable_set('xmlsitemap_regenerate_needed', TRUE);
   }

-  if (empty($sitemap->smid)) {
+  if (!empty($sitemap->smid)) {
     drupal_write_record('xmlsitemap_sitemap', $sitemap);
     module_invoke_all('xmlsitemap_sitemap_insert', $sitemap);
   }
digi24’s picture

Status: Needs review » Needs work

One more addition:
the patch above still was not sufficient, as sitemap creation remains broken (I had a rather large sitemap so it was not obvious), I have added the is_object check and separate typecasting to xml_sitemap_save and now it seems to work better.

I think I identified the problem, would be nice if somebody familiar with the object handling in xmlsitemaps could have a look at it.

digi24’s picture

another correction for the empty statement:

function xmlsitemap_sitemap_save(stdClass &$sitemap) {
  if(!is_object($sitemap)){
    $sitemap = (object) $sitemap;
  }
  xmlsitemap_load_all_includes();

  // Make sure context is sorted before saving the hash.
  $smid_old = isset($sitemap->smid) ? $sitemap->smid : NULL;
  $sitemap->smid = xmlsitemap_sitemap_get_context_hash($sitemap->context);

  // If the context was changed, we need to perform additional actions.
  if (isset($smid_old) && $sitemap->smid != $smid_old) {
    // Rename the files directory so the sitemap does not break.
    $old_sitemap = (object) array('smid' => $smid_old);
    $old_dir = xmlsitemap_get_directory($old_sitemap);
    $new_dir = xmlsitemap_get_directory($sitemap);
    xmlsitemap_directory_move($old_dir, $new_dir);

    // Change the smid field so drupal_write_record() does not fail.
    db_query("UPDATE {xmlsitemap_sitemap} SET smid = '%s' WHERE smid = '%s'", $sitemap->smid, $smid_old);

    // Mark the sitemaps as needing regeneration.
    variable_set('xmlsitemap_regenerate_needed', TRUE);
  }

  if (empty($smid_old)) {
    drupal_write_record('xmlsitemap_sitemap', $sitemap);
    module_invoke_all('xmlsitemap_sitemap_insert', $sitemap);
  }
  else {
    drupal_write_record('xmlsitemap_sitemap', $sitemap, array('smid'));
    module_invoke_all('xmlsitemap_sitemap_update', $sitemap);
  }

  return $sitemap;
}
Dave Reid’s picture

Status: Needs work » Fixed

Alright I'm very sure I have this all fixed now. I went through and manually tested sitemap addition, editing, and deletion on both D6 and D7 and they all work with no errors.

tomsm’s picture

Just installed and tested latest dev (2010-Sep-30). Everything is OK.

Vacilando’s picture

My sitemaps disappeared. When running cron manually, I get "Cron run failed, disabled or nothing to do".

Updated from previous 6.x-2.x-dev to the latest of 2010-Sep-30 and ran /update.php

Unfortunately, I still get PHP Fatal error: Cannot use object of type stdClass as array in /.............../sites/all/modules/xmlsitemap/xmlsitemap.xmlsitemap.inc

Dave Reid’s picture

@vacilando: I'm missing the line number from that error message that is the most helpful information.

Vacilando’s picture

Apologies. It's line 186.

Dave Reid’s picture

Status: Fixed » Postponed (maintainer needs more info)

Hrm, I can't confirm this. Are you using any sub-modules that integrate with XML sitemap? Try updated to latest development versions for all?

Vacilando’s picture

Not sure why, but I am not getting this error anymore.

  • Dave Reid committed 38853e8 on 8.x-1.x
    #921644 by Dave Reid: Fixed sitemap arrays being passed to...
  • Dave Reid committed 5147611 on 8.x-1.x
    #921644 by Dave Reid: Fixed not able to save sitemaps.
    
    
  • Dave Reid committed 59c002d on 8.x-1.x
    #921644 by Dave Reid: Fixed sitemap arrays being passed to...
  • Dave Reid committed 6f467ae on 8.x-1.x
    #921644 by Dave Reid: Fixed object/array with...