Hi,

Recently we upgrade from drupal version 5.13 to 6.26.
We are having the following warning message when we try to create a new album:

warning: Invalid argument supplied for foreach() in /home/abreojog/public_html/sites/all/modules/acidfree/acidfree.module on line 661.

I looked into this code and it has

function _acidfree_check_in_taxonomy ($taxonomy, $value) {
    foreach ($taxonomy['#options'] as $option) {
        if (isset($option) && is_object($option) &&
           array_key_exists ($value, $option->option)) return TRUE;
    }
    return FALSE;
}

I added verification to the $taxonomy['#options'] variable but I'm not sure if this will have any unknown impact.

function _acidfree_check_in_taxonomy ($taxonomy, $value) {
  if (is_array($taxonomy) && is_array($taxonomy['#options'])) {
    foreach ($taxonomy['#options'] as $option) {
        if (isset($option) && is_object($option) &&
           array_key_exists ($value, $option->option)) return TRUE;
    }
  }
  return FALSE;
}

Can you please help us?

Comments

mwheinz’s picture

So, the issue here is that Acidfree albums are actually taxonomy (vocabulary) terms - the same way forums are. The taxonomy terms *should* be getting automatically added to the form by drupal itself.

For example, in my personal site, I hacked up _acidfree_check_in_taxonomy to dump the contents of $taxonomy:

function _acidfree_check_in_taxonomy ($taxonomy, $value) {

    drupal_set_message("<pre>".t(print_r($taxonomy,true))."</pre>");
    foreach ($taxonomy['#options'] as $option) {
        if (isset($option) && is_object($option) &&
           array_key_exists ($value, $option->option)) return TRUE;
    }
    return FALSE;
}

And here's what I got when I tried to create an album:

Array
(
    [#type] => select
    [#title] => Parent
    [#default_value] => 171
    [#options] => Array
        (
            [] => 
            [0] => stdClass Object
                (
                    [option] => Array
                        (
                            [165] => A's Acidfree album
                        )

                )

            [1] => stdClass Object
                (
                    [option] => Array
                        (
                            [164] => B's Acidfree album
                        )

                )

            [2] => stdClass Object
                (
                    [option] => Array
                        (
                            [7] => Photos
                        )

                )

            [3] => stdClass Object
                (
                    [option] => Array
                        (
                            [127] => -2009
                        )

                )

            [4] => stdClass Object
                (
                    [option] => Array
                        (
                            [106] => --2009-Fourth-Of-July
                        )

                )

.
. (lots of stuff deleted)
.

            [124] => stdClass Object
                (
                    [option] => Array
                        (
                            [84] => -Valley Forge
                        )

                )

        )

    [#description] => 
    [#multiple] => 0
    [#size] => 0
    [#weight] => -15
    [#theme] => taxonomy_term_select
  1. Exactly what steps are you doing to create this album?
  2. Does the album get created?
  3. Does any album exist yet or is this your very first?
  4. If you dump out taxonomy the way I did, what do you see?
tmgd’s picture

1. I go to Create Album ( with url http:///node/add/acidfree )
2. Yes; The warning appears as soon as I go to the url http:///node/add/acidfree but I can create the album normally
3. There are lots of albums (created in drupal version 5.13 or before that)
4. I made the hack that you suggest and the array is empty. I see, at the start of the page, an empty grey box (with maybe 600x50 pixels)

tmgd’s picture

Does anybody have an idea about what could be the reason of this problem and how can we solve it?

Thanks

tmgd’s picture

1. I go to Create Album ( with url http:///node/add/acidfree )
2. Yes; The warning appears as soon as I go to the url http:///node/add/acidfree but I can create the album normally
3. There are lots of albums (created in drupal version 5.13 or before that)
4. I made the hack that you suggest and the array is empty. I see, at the start of the page, an empty grey box (with maybe 600x50 pixels)

mwheinz’s picture

Basically, it sounds like your taxonomy/vocabularies are messed up: taxonomy is not providing the vocabulary information when the acidfree form is displayed.

I'm afraid that the only answer that comes to mind is that you didn't follow the instructions for upgrading acidfree from 5.x to 6.x: you have to completely disable acidfree before upgrading, then reinstall acidfree.

I really don't want to push this back on you, but if that's the case, I can't think of anyway to help without finding an expert in drupal taxonomy who can straighten it out.

tmgd’s picture

Hi,

I disabled all the modules (not in the core) that I used in drupal 5.x
Only after that, I upgraded drupal to 6.x
After having the server running in drupal 6.x, I put the 6.x Acidfree version in the server and run the update.php script.
After that, I enabled the Acidfree module.

tmgd’s picture

I looked into vocabulary tables and I have duplicated name entries (with different vid and module).
In table vocabulary I have twice "Acidfree albums" name, but one has vid 15 (with module taxonomy) and vid 18 (with module acidfree).

Anyone knows if this is correct?

Thanks

mwheinz’s picture

It's impossible to say which is the right one vocabulary id numbers are assigned by taxonomy. For example, on my site, the vocab id is 6.

I still cannot give you a guaranteed fix for this problem but - check the value of acidfree_vocab_id in the "variable" table.

I can think of a couple of things you could try but they are destructive:

I CANNOT PROMISE THIS WILL WORK! This is like asking a doctor to describe how to remove a tumor over the phone, without having ever seen the tumor.

1. Put the site in maintenance mode.
2. Make a complete backup of your database.
3. Use Admin/content to make a list of the node ids of all your albums. Save this list, in case you need it later.
4. Check the two vocabularies you have. Figure out which one you want to keep. Delete the other vocabulary. Make sure 'acidfree_vocab_id' points to the vocabulary you have left.

If this solves the problem, great. If it doesn't restore your old data from backup!

mwheinz’s picture

The only other solution I can suggest is to:

1. Put the site in maintenance mode.
2. Make a backup.
3. Completely uninstall acidfree.
4. Delete any acidfree vocabularies left in taxonomy.
5. Re-install acidfree.
6. Recreate your albums.

tmgd’s picture

Deleted the new duplicated entry in the vocabulary table (entry with vid 18).

After that, I updated the vid from acidfree_vocab_id name that was present in variable table,
UPDATE `variable` SET `value` = 's:2:"15";' WHERE `name` = 'acidfree_vocab_id';

To finish, I updated term_data table to the old vid (there were some entries with the new vid and others with the old vid).
UPDATE `term_data` SET vid=15 WHERE vid=18;

Problem solved.

I believe the problem was due to some bug with the upgrade.

Thanks for your help.

mwheinz’s picture

Status: Active » Closed (cannot reproduce)

Phew!

I'm so glad you were able to recover; sorry I couldn't be more help!

tmgd’s picture

I really appreciate your help.
We all know how difficult is to identify this kind of bugs.
... and it was with some of your ideas that I get into the problem.
Thanks