| 1 |
<?php
|
| 2 |
// $Id: update-weblinks.php,v 1.2.4.1 2007/01/28 03:54:19 syscrusher Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* PHP page for updating legacy "weblink" nodes, from the new table format from
|
| 7 |
* Drupal 4.6.
|
| 8 |
*
|
| 9 |
* Adapted from a patch contributed by John Hwang.
|
| 10 |
*
|
| 11 |
* WARNING 1: This script works ONLY with Ber Kessels' new weblink.module for
|
| 12 |
* Drupal 4.6. Use update-weblinks-old.php instead for older versions!
|
| 13 |
*
|
| 14 |
* WARNING 2: Monitoring is not yet supported, and therefore this script does not
|
| 15 |
* migrate URL monitoring parameters. If you need that feature, you need to wait
|
| 16 |
* a bit before deploying the new links package.
|
| 17 |
*
|
| 18 |
* WARNING 3: This script plays a little fast and loose with {links}.last_click_time
|
| 19 |
* in a few cases. For the vast majority of links, it will get the correct value.
|
| 20 |
* In the rare case where two links that were different in the old weblinks
|
| 21 |
* module but which normalize to the same {links} record in the Links Package,
|
| 22 |
* this converter uses the last value for last_click_time that it encounters.
|
| 23 |
* So it isn't guaranteed to get the absolute latest value in those rare cases.
|
| 24 |
* This is a byproduct of the fact that the old weblinks module prevented exact
|
| 25 |
* duplicate links but did not rigorously normalize and rationalize them.
|
| 26 |
*
|
| 27 |
* TO USE: First, update your site to Drupal 4.7 so that your {node} table gets
|
| 28 |
* converted.
|
| 29 |
*
|
| 30 |
* Second, install the new links module package, including links_related and
|
| 31 |
* links_weblink.
|
| 32 |
*
|
| 33 |
* Next, copy this script to your Drupal root directory (the "top level" of
|
| 34 |
* your Drupal site) and run it. It will convert no more than 1000 links at
|
| 35 |
* a time, to minimize the chance of timeouts. You can safely re-run the
|
| 36 |
* script multiple times.
|
| 37 |
*
|
| 38 |
* THIS CODE IS EXPERIMENTAL -- NOT FOR PRODUCTION USE
|
| 39 |
*/
|
| 40 |
|
| 41 |
require_once './includes/bootstrap.inc';
|
| 42 |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
|
| 43 |
|
| 44 |
$sql = "SELECT DISTINCT n.nid, n.title, wl.*, wln.link_title, wln.weight FROM {node} n INNER JOIN {weblinks_node} wln ON n.nid=wln.nid INNER JOIN {weblinks} wl ON wl.lid=wln.lid LEFT JOIN {links_node} ln ON wln.nid=ln.nid WHERE n.type='weblink' AND ln.nid IS NULL LIMIT 1000";
|
| 45 |
$sql2 = "INSERT INTO {links_node} (lid,nid,link_title,weight,clicks,module) values (%d,%d,'%s',%d,%d,'links_weblink')";
|
| 46 |
$sql3 = "UPDATE {links} SET last_click_time=%d WHERE lid=%d";
|
| 47 |
|
| 48 |
print('<html><body>');
|
| 49 |
$count=0;
|
| 50 |
$result = db_query($sql);
|
| 51 |
while ($row = db_fetch_object($result)) {
|
| 52 |
$n_url = links_normalize_url($row->url);
|
| 53 |
if (empty($n_url)) {
|
| 54 |
print("<br>Node ".$row->nid." was not converted (empty URL)");
|
| 55 |
continue;
|
| 56 |
}
|
| 57 |
$lid = links_put_link($n_url);
|
| 58 |
if (! $lid) {
|
| 59 |
print("<br>Node ".$row->nid." was not converted (failed link insert)");
|
| 60 |
continue;
|
| 61 |
}
|
| 62 |
links_delete_links_for_node($row->nid);
|
| 63 |
$title = links_suggest_link_title($lid, (empty($row->link_title) ? $row->title : $row->link_title));
|
| 64 |
$clicks = $row->clicks;
|
| 65 |
$clicktime = $row->last_click_time;
|
| 66 |
$result2 = db_query($sql2, $lid, $row->nid, $title, $row->weight, $clicks);
|
| 67 |
$result3 = db_query($sql3, $clicktime, $lid);
|
| 68 |
$count++;
|
| 69 |
}
|
| 70 |
print("<P>Processed $count weblink records. The script limits the number in one run to prevent timeouts. If no errors, rerun this script until the count is zero; it may take several iterations.");
|
| 71 |
print("<P>WARNING: Monitoring parameters are not yet supported and are currently ignored.");
|
| 72 |
print('</body></html>');
|
| 73 |
?>
|