Archive

Archive for the ‘Uncategorized’ Category

WinSCP console hangs while installing with yum

February 13, 2011 Leave a comment

This seemed very wierd to me.

Here’s what i used to get before it “hung”

[root@xxxx ~]# yum install mod_dav_svn
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: centos.mirror.iweb.ca
* base: centos.mirror.iweb.ca
* epel: mirror.csclub.uwaterloo.ca
* extras: centos.mirror.iweb.ca
* updates: centos.mirror.iweb.ca
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package mod_dav_svn.x86_64 0:1.4.2-4.el5_3.1 set to be updated
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mod_dav_svn x86_64 1.4.2-4.el5_3.1 base 70 k

Transaction Summary
================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)

Total download size: 70 k

Host is not communicating for more than 15 seconds. Still waiting….

Warning: Aborting this operating will close the connection.

As it turned out, it was waiting for user input

“Is this ok[y/N]”

Solution: ? The “-y” flag of yum

yum-y install mod_dav_svn

Drupal 7 – Programatically Create Nodes

December 6, 2010 12 comments

Getting straight to the topic,

From drupal 6, there have been some small changes in the way users can create a node programatically. Like for eg. instead of using the drupal_execute function, we now have to use drupal_form_submit. Both these functions do the same thing, i.e, submit the form programatically.

Since, I experimented with creating book nodes, i’ll be running through the same example.

Minimally, 3 arguments need to be specified to the drupal_form_submit function in this case.

The first one, is the form id. This id can be got by taking a quick look at the form POST parameters while creating a book “normally”. I did that by using firebug on the node/add/book page.

The 2nd argument is an array of form values that should mimic the values posted from the browser. The focus should be to copy the (relevant) variable names that are seen while analyzing the post request. See below,


The values should go within an array keyed by the key ‘values’

global $user;
// Body Structure
// For more information on how this variable is read by the form engine, see
// drupal_array_get_nested_value.
// Substitute the language "en" for the language of the node. Make sure that
// the appropriate locale is enabled
$body["en"][0]['value'] = "Some body text";

$formState['values']['title'] = "Title of the book"
$formState['values']['language'] = "en"; // substitute for the language of the node
$formState['values']['name'] = $user->name;
$formState['values']['body'] = $body;
$formState['values']['status'] = 1;
$formState['values']['promote'] = 0;
$formState['values']['sticky'] = 0;
$formState['values']['op'] = t('Save');

And the last argument is a node object reference that one must create with the necessary information.

$newNode = array(
 'type' => 'book',
 'book' => array(
 'bid' => $node->book['bid'], // use 'new' here if the book page is of a new book
 'plid' => $node->book['mlid'],
 'weight' => $chapNo,
 'options' => array(),
 'has_children' => 0,
 'module' => 'book'
 ),
 'language' => $node->language // This is needed
);

Last thing to do is to call the drupal_form_submit function.

drupal_form_submit('book_node_form', $formState, (object) $newNode);

Thats it! We’re done!