I had defined a simple "website" content type that is a title, a description, and a "weburl". The weburl module came with a version of CCK I had installed on 4.7.x. I've created several hundred of these "website" nodes.

I just did a trial conversion of my site (yes on a test install) using drupal 5.1 with CCK 5.x.1.3.

The "weburl" field is described as being a "Text Field" with URL checking capabilities. It would be nice if that field converted to a Link type on upgrade.

Alternatively I'd like some instructions on how to do the conversion. Obviously I can create a Link field in the 5.1 instance, then write a program to read through the node_field_weburl_data table in the 4.7.x instance and copy that data to an appropriate place in the 5.1 instance...... but I don't know where to copy the data.

Comments

reikiman’s picture

To follow up... I read the handbook pages on updating CCK and see the recommendation to upgrade the CK in the 4.7.x instance to the latest version. I think I'm not at the latest. So I'll try that.

reikiman’s picture

To follow up again... I updated (the test copy of) my site to drupal 4.7.6 then to CCK 4.7.x-1.3. This made no difference for my weburl fields, they were still ignored and not converted during the upgrade to drupal5.1+CCK5.x-1.3.

Curiously the weburl module was missing from the CCK 4.7.x-1.3 package. I suppose this means that at some time in CCK's history y'all decided to drop that sub-module...? It would be real nice at the moment to have a migration path. As I said, I have hundreds of nodes that use this field type.

I tried reading through the cck.install file so I could get an idea of what the schema is nowadays. But it's more obtuse than you can imagine. It starts out with a nice clean pair of table definitions but there's all these update_xyzzy functions that have changed everything around and it makes it completely hard to figure out what the result is supposed to be. Eek.

reikiman’s picture

Okay, despite the obtusity of the schema I think I see a manual migration route.

First, the old weburl data is in a table node_field_weburl_data such that node_field_weburl_data.nid is the node ID, and node_field_weburl_data.field_weburl is the URL I'm interested in.

Second, I added a Link field to my website content type. The data for this is in the table content_type_content_website with the field nid having the node ID, and the field field_url_0_url having the URL. I could duplicate the title into field_url_0_title.

It seems like a simple script to convert this.

reikiman’s picture

Priority: Critical » Normal

Here's my script. I'd be curious for any critiques.


if ($db = mysql_connect('localhost:8889', 'root', 'root')) {
  mysql_select_db('new7gen');
  $result = mysql_query('SELECT node.nid as nid, node_field_weburl_data.field_weburl as field_weburl, node.title as title FROM node, node_field_weburl_data WHERE node.nid = node_field_weburl_data.nid', $db);
  while ($row = mysql_fetch_assoc($result)) {
    if ($res2 = mysql_query('SELECT nid FROM content_type_content_website WHERE nid = '.$row['nid'])) {
      if (mysql_num_rows($res2) > 0) {
        $query = sprintf("UPDATE content_type_content_website SET field_url_0_url = '%s', field_url_0_title = '%s' WHERE nid = %d",
          mysql_real_escape_string($row['field_weburl'], $db),
          mysql_real_escape_string($row['title'], $db),
          $row['nid']);
        mysql_query($query, $db);
      } else {
        $query = sprintf("INSERT INTO content_type_content_website (vid, nid, field_url_0_url, field_url_0_title, field_url_0_attributes) "
                ." VALUES(%d,%d,'%s','%s','N;')",
                $row['nid'], $row['nid'],
                mysql_real_escape_string($row['field_weburl'], $db),
                mysql_real_escape_string($row['title'], $db));
        mysql_query($query, $db);
      }
    }
  }
}
reikiman’s picture

Ah, I just noticed the passwords and stuff I copied into the code. That could have been a major flubbo, except... it's for the MAMP instance on my Mac, not on any production server, and in any case the Mac is behind a firewall. So while I made a mistake, it's not a problem, so don't anybody go raising any alarm bells.

nilard’s picture

Version: 5.x-1.3 » 5.x-1.x-dev

Here is my way of converting weburl fields. First, you should create a link field named 'link', then run the following script:


  require_once './includes/bootstrap.inc';
  drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
  drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);

  $result = db_query("SELECT nid FROM {node}");

  while($node = db_fetch_object($result)) {

    $node = node_load($node->nid);

    if (empty($node->field_link)) {
      $weburl = db_result(db_query("SELECT field_weburl FROM {node_field_weburl_data} WHERE nid = %d", $node->nid));
      if (!empty($weburl)) {
        $node->field_link[0]['url'] = $weburl;
        $node->field_link[0]['title'] = $node->title;
        node_save($node);
      }
    }

  }

karens’s picture

Status: Active » Closed (won't fix)

The D5 version is no longer being supported. Sorry.