/imagefield_migrate.php" title="http:///imagefield_migrate.php" rel="nofollow">http:///imagefield_migrate.php in your browser. * - Remove this script from your site to prevent accidental re-run. * - Disable and uninstall image and image_attach modules. * * KNOWN ISSUES * ------------ * - Rename files that have a '+' in them in the files table and also rename in filesystem * * AUTHORS * ------- * spydor (see http://drupal.org/node/201983#comment-828698) * Moshe Weitzman (http://drupal.org/moshe) * hobbes_vt * rkeppner */ require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // ***** CONFIGURATION ******* // Table prefix ... in case you use it - otherwise leave blank $table_pfx = ''; // The imagefield field that you have already created and configured as per Prerequisites. $field_name = 'field_obrazek'; // The content type that you have already created as per Prerequisites. $type_name = 'obrazek'; // ***** END CONFIGURATION ******* // Populate the imagefield table for every image node. $table_content_type = $table_pfx. 'content_type_'. $type_name; // this changed from the original version $table_content_field = $table_pfx. 'content_'. $field_name; $fid = $field_name. '_fid'; $list = $field_name. '_list'; $data = $field_name. '_data'; $table_node = $table_pfx. 'node'; // add prefix $table_files = $table_pfx. 'files'; // add prefix $table_upload = $table_pfx. 'image'; // add prefix $sql = "INSERT INTO {$table_content_type} (vid, nid) SELECT n.vid, n.nid FROM {$table_node} n INNER JOIN {$table_upload} u ON n.nid = u.nid INNER JOIN {$table_files} f ON u.fid = f.fid WHERE n.type = 'image' AND f.filename = '_original'"; echo $sql.'
'; if (db_query($sql)) { echo "- $table_content_type populated.
\n"; } else { echo "- $table_content_type NOT populated.
\n"; } $sql = "INSERT INTO {$table_content_field} (vid, nid, delta, $fid, $list, $data) SELECT n.vid, n.nid, 0, f.fid, 1, CONCAT('a:1:{s:11:\"description\";s:', CHAR_LENGTH(n.title), ':\"', n.title, '\";}') FROM {$table_node} n INNER JOIN {$table_upload} u ON n.nid = u.nid INNER JOIN {$table_files} f ON u.fid = f.fid WHERE n.type = 'image' AND f.filename = '_original'"; echo $sql.'
'; if (db_query($sql)) { echo "- $table_content_field populated.
\n"; } else { echo "- $table_content_field NOT populated.
\n"; } // Set the needed filename in the files table. $image_path = file_create_path(variable_get('image_default_path', 'images')); $length = strlen($image_path)+2; $sql = "UPDATE {$table_files} SET filename = SUBSTRING(filepath, $length) WHERE filename = '_original'"; echo $sql.'
'; if (db_query($sql)) { echo "- files table updated
\n"; } else { echo "- files table NOT updated
\n"; } // Change the content type from 'image' to the configured type. $sql = "UPDATE {$table_node} SET type = '%s' WHERE type = 'image'"; echo $sql.'
'; db_query($sql, $type_name); // Loop over the image_attach records if (module_exists('image_attach')) { $table_image_attach = $table_pfx. 'image_attach'; // add prefix $sql = "SELECT n.nid, n.vid, ia.iid FROM {$table_image_attach} ia INNER JOIN {$table_node} n ON ia.nid=n.nid"; $result = db_query($sql); echo $sql.'
'; $num = 0; while ($row = db_fetch_object($result)) { $num++; echo "UPDATE the imagefield to point to the attached node, not the standalone node"; $sql = "UPDATE $table_content_type SET nid = $row->nid, vid = $row->vid WHERE nid = $row->iid"; echo $sql.'
'; if (!db_query($sql)) { echo "update $table_content_type failed for $row->iid
\n"; } $sql = "UPDATE $table_content_field SET nid = $row->nid, vid = $row->vid WHERE nid = $row->iid"; if (db_query($sql)) { echo "Successful update. Now unpublish the standalone node that we just made."; $sql = "UPDATE {$table_node} SET status = 0 WHERE nid = $row->iid"; echo $sql.'
'; db_query($sql); } else { echo "update $table_content_field failed for $row->iid
\n"; } } echo "- $num image_attach relationships were migrated.
\n"; } if (module_exists('video_image')) { // Loop over the video.module nodes. Migrate video_image thumbnails to imagefield. $sql = "SELECT nid, vid FROM {$table_node} WHERE type = 'video'"; echo $sql.'
'; $result = db_query($sql); $num = 0; while ($row = db_fetch_object($result)) { $num++; $node = node_load($row->nid); if ($iid = $node->iid) { $sql = "UPDATE {$table_content_type} SET nid = $row->nid, vid = $row->vid WHERE nid = $iid"; echo $sql.'
'; if (db_query($sql)) { echo "Successful update. Now unpublish the standalone node that we just made."; $sql = "UPDATE {$table_node} SET status = 0 WHERE nid = $iid"; echo $sql.'
'; db_query($sql); } else { echo "update $table failed for $iid
\n"; } }; } echo "- $num video.module thumbnails were migrated.
\n"; } // Clear CCK cache. $table_cache_content = $table_pfx. 'cache_content'; // add prefix $sql = "DELETE FROM {$table_cache_content}"; echo $sql.'
'; db_query($sql); ?>