Hallo,
I'm using taxonomy_defaults on 27 sites, and it would be very handy for me to be able to:

  • set the default term and
  • set the vocabulary as 'hidden'

by deploying a php script via drush. It seems to me that I could accomplish both by setting the involved variables by:

<?php
variable_set("taxdef_mytype_5_visible", FALSE);
variable_set("taxdef_mytype_5", 20);
?>

where 5 and 20 are vid and tid respectively. Do you think this is going to work? Do I have to invoke any module before that?

Also, is there a way to retroactively assign a term to already created nodes? I could modify the node_term table, but I'm hoping there is a less brutal solution...

Thanks in advance,

L.F.

Comments

bradweikel’s picture

I can't speak to the Drush side of this, since I've not written any drush commands (although it looks pretty straightforward according to the sandwich example on the Drush project page), but in terms of the Taxonomy Defaults that looks about right, although the term id should actually be in an array:

variable_set("taxdef_mytype_5", array(20));

As for retroactive assignment, you could use the Views Bulk Operation module to avoid direct SQL wrangling, but I've steered clear of retroactive stuff in the Taxonomy Defaults module because I don't want to bloat the module with a bunch of different configuration options for those sorts of changes.

If you get a full drush command put together, will you attach it to this issue? I'm sure others will be interested...

lucio.ferrari’s picture

I only tried this using devel module's "Execute PHP Code" block, but it seems to work.

My aim is to create a vocabulary with only one term, hide the vocabulary and set the term as default.
This will be used in conjunction with 'nodeorder' module and a view to order posts promoted to front page (the part involving nodeorder seems to be not so easily automatized, unfortunately...)

<?php

//
// script.php
//

// Define and save vocabulary

 $vocab = array(
    'name' => t('Order'),
    'description' => t('To order things'),
    'nodes' => array('MyType1' => 1,
                     'MyType2' => 1,
                     'MyType3' => 1,
                     'MyType4' => 1,
                     'MyType5' => 1),
    'hierarchy' => 0,
    'relations' => 0,
    'tags' => 0,
    'multiple' => 0,
    'required' => 0,
    'weight' => 5,
  );

 taxonomy_save_vocabulary($vocab);

// Find its vid ---- maybe $vocab->vid is enough, but I chose the long and safe route

$result = db_query("SELECT {vid} FROM {vocabulary} WHERE name = '%s'",  'Order'); 

while ( $obj = db_fetch_object ($result) ) {
  $vid = $obj->vid;
}

// Define and save term

  $term = array(
    'vid' => $vid, 
    'name' => 'Front page', // Term Name
  );

  taxonomy_save_term($term);

// Find its tid --- as above, maybe $term->tid is enough

$result = db_query("SELECT {tid} FROM {term_data} WHERE name = '%s'", 'Front page'); 

while ( $obj = db_fetch_object ($result) ) {
  $tid = $obj->tid;
}

// An array defining the content types which the term is to be added to --- I could have defined it earlier, and used it to define the vocabulary, but I'm not a good coder anyway

$types = array( 
	'MyType1',
	'MyType2',
	'MyType3',
	'MyType4',
	'MyType5',
	);


// Make vocabulary invisible for 'types'

foreach($types as $type) {

		variable_set('taxdef_'.$type.'_'.$vid.'_visible', FALSE);
		
}



// Set 'First page' as default term

foreach($types as $type) {

		variable_set('taxdef_'.$type.'_'.$vid, array($tid) );
		
}

?>

I'll execute this code as:

drush -r /path/to/root -l http://www.example.ch scr script.php

Then, I guess I'm going to brutalize the database to add the tid of 'Front page' to nodes as needed.