Index: comment_upload.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/comment_upload/comment_upload.install,v retrieving revision 1.4.2.5 diff -u -r1.4.2.5 comment_upload.install --- comment_upload.install 11 Dec 2008 11:02:11 -0000 1.4.2.5 +++ comment_upload.install 26 Jan 2009 18:56:11 -0000 @@ -161,10 +161,15 @@ * Implementation of hook_update_N(). */ function comment_upload_update_6000() { + + $ret = array(); + + if (!isset($_SESSION['comment_upload_update_6000'])) { + $schema['comment_upload'] = array( - 'description' => t('Stores uploaded file information and table associations.'), - 'fields' => array( - 'fid' => array( + 'description' => t('Stores uploaded file information and table associations.'), + 'fields' => array( + 'fid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, @@ -212,21 +217,36 @@ 'indexes' => array( 'cid_fid' => array('cid', 'fid'), 'nid' => array('nid'), - ), - ); + )); + db_create_table($ret, 'comment_upload', $schema['comment_upload']); - $ret = array(); + // Add a converted field so the batch processing knows when to stop. + db_add_field($ret, 'comment_upload_files', 'converted', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny')); + } - db_create_table($ret, 'comment_upload', $schema['comment_upload']); + $limit = 1; // TODO: set to 50 or so, 1 is for testing purposes ... - $result = db_query("SELECT cuf.*, c.uid FROM {comment_upload_files} cuf INNER JOIN {comments} c ON cuf.cid = c.cid"); - while ($file = db_fetch_object($result)) { + // Select all the uploaded files that haven't been converted yet. + $result = db_query("SELECT cuf.*, c.uid FROM {comment_upload_files} cuf INNER JOIN {comments} c ON cuf.cid = c.cid WHERE cuf.converted = 0"); + while ($limit && ($file = db_fetch_object($result))) { db_query("INSERT INTO {files} (filename, filepath, filemime, filesize, uid, status) VALUES ('%s', '%s', '%s', %d, %d, %d)", $file->filename, $file->filepath, $file->filemime, $file->filesize, $file->uid, 1); $fid = db_last_insert_id('files', 'fid'); db_query("INSERT INTO {comment_upload} (fid, nid, cid, description, list) VALUES (%d, %d, %d, '%s', %d)", $fid, $file->nid, $file->cid, $file->description, $file->list); + db_query('UPDATE {comment_upload_files} SET converted = 1 WHERE fid = %d', $file->fid); + $_SESSION['comment_upload_update_6000']++; + $limit--; + } + + if ($file) { + $ret['#finished'] = 0; + } + else { + unset($_SESSION['comment_upload_update_6000']); + db_drop_table($ret, 'comment_upload_files'); + $ret['#finished'] = 1; } - db_drop_table($ret, 'comment_upload_files'); + return $ret; }