Comment 1 for bug 1239461

Revision history for this message
Robert Lyon (robertl-9) wrote :

Thoughts on sorting this out - will need a script to do:

Step 1: Find the duplicate feed urls: (1 db call)

SELECT COUNT(url), url, authuser, authpassword FROM {blocktype_externalfeed_data} GROUP BY url, authuser, authpassword HAVING COUNT(url) > 1 ORDER BY COUNT(url);

step 2: get the feed ids and use the 1st one to be the feed id for the block instances: (many db calls depending on how many rows from step 1 have duplicates)

SELECT id FROM {blocktype_externalfeed_data} WHERE url = ?, authuser = ?, authpassword = ?;

- add the ids to an $array[$duplicatefeed]['ids'][] and use 'ids'[0] as the 'true' id

step 3: Find the block instances using external feeds. (1 db call). Check to see if they are not using the 'true' id and update them accordingly:

SELECT id FROM {block_instance} WHERE blocktype = 'externalfeed';

- get block_instance object and get $blockfeedid from object
$blockinstance = new BlockInstance($blockid);
$configdata = $blockinstance->get('configdata');
if (!empty($configdata['feedid'])) {
    foreach ($array as $duplicatefeed => $ids) {
        foreach ($ids as $key => $id) {
            if ($id == $configdata['feedid'] && $key != '0') {
         // not using the first instance id of this feed
                $configdata['feedid'] = $ids[0];
  $blockinstance->set('dirty') = true;
                $blockinstance->commit(); (possibly very many db calls)
                break;
            }
        }
    }
}

step 4: delete the now orphaned feed id(s) rows

foreach ($array as $duplicatefeed => $ids) {
    foreach ($ids as $key => $id) {
        if ($key != '0') {
            DELETE FROM {blocktype_externalfeed_data} WHERE id = ? (possibly very many db calls)
        }
    }
}

Currently I'm thinking that this approach may use too many db calls. But not sure how to get feedid from configdata column in an easier way. Maybe a preg_match on the serialized data?