1

I'm trying to reset all field_flag fields of all terms of a taxonomy value, where field_flag is TRUE (or 1).

Does anyone know how to do that?

Maybe some more back-story: I have a rule that gets fired on creation and editing of a taxonomy term when it has the field_flag in it. Now out of this I want to "reset" all field_flags since only one term can have that field checked.

Thanks!

0

To clarify, you have created a new flag using the Flag module and attached it to a taxonomy bundle (either terms or vocabularies) and want to reset these flags.

You can do this directly in your database with a couple commands. First, you need the Flag ID of your flag which is in the 'flags' table:

mysql> desc flags;
+--------------+----------------------+------+-----+---------+----------------+
| Field        | Type                 | Null | Key | Default | Extra          |
+--------------+----------------------+------+-----+---------+----------------+
| fid          | smallint(5) unsigned | NO   | PRI | NULL    | auto_increment |
| content_type | varchar(32)          | NO   |     |         |                |
| name         | varchar(128)         | YES  | UNI |         |                |
| title        | varchar(255)         | YES  |     |         |                |
| global       | tinyint(4)           | YES  |     | 0       |                |
| options      | text                 | YES  |     | NULL    |                |
+--------------+----------------------+------+-----+---------+----------------+

You can find this by selecting the fid, and name from flags:

mysql> select fid, name from flags;
+-----+---------------+
| fid | name          |
+-----+---------------+
|   1 | bookmarks     |
|   3 | taxonomy_flag |
+-----+---------------+

In my development server, the taxonomy_flag id is 3. Now take a look at the flag_content table where all the flag content data is stored:

mysql> desc flag_content;
+--------------+----------------------+------+-----+---------+----------------+
| Field        | Type                 | Null | Key | Default | Extra          |
+--------------+----------------------+------+-----+---------+----------------+
| fcid         | int(10) unsigned     | NO   | PRI | NULL    | auto_increment |
| fid          | smallint(5) unsigned | NO   | MUL | 0       |                |
| content_type | varchar(128)         | NO   | MUL |         |                |
| content_id   | int(10) unsigned     | NO   | MUL | 0       |                |
| uid          | int(10) unsigned     | NO   |     | 0       |                |
| sid          | int(10) unsigned     | NO   |     | 0       |                |
| timestamp    | int(10) unsigned     | NO   |     | 0       |                |
+--------------+----------------------+------+-----+---------+----------------+

What you want to do to reset all the values for your target flag is delete all entries from the flag_content table, so in my example above that would be

delete from flag_content where fid=3;
  • Nope, I'm using a drupal-standard boolean field. No flag module was installed. I know I could do that with just some MySQL commands. I also know I can do that with just some lines of PHP. But I want it the Drupal way :) – lumio May 21 '13 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.