External feed has duplicate rows causing problems
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mahara |
Fix Released
|
High
|
Unassigned |
Bug Description
Older sites can end up with multiple rows in the blocktype_
This causes problem when one tries to add a new rss feed block to a page if there is more than one row in the db of the same feed url.
[WAR] bc (lib/errors.
Call stack (most recent first):
log_
log_
SQLExceptio
get_
get_
ensure_
PluginBlock
To sort this out we are going to need a script in the the lib/db/upgrade.php to handle the clearing out of the duplicate rows and making sure the block instance configdata now points to the 1 row left in the db.
Changed in mahara: | |
milestone: | 1.8.1 → 1.8.2 |
Changed in mahara: | |
status: | In Progress → Fix Committed |
Changed in mahara: | |
status: | Fix Committed → Fix Released |
Changed in mahara: | |
status: | Fix Released → Fix Committed |
milestone: | 1.8.2 → 1.9.0 |
Changed in mahara: | |
status: | Fix Committed → Fix Released |
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 $blockid) ; >get('configdat a'); $configdata[ 'feedid' ])) { 'feedid' ] && $key != '0') {
$configdata[ 'feedid' ] = $ids[0]; e->set( 'dirty' ) = true;
$blockinstanc e->commit( ); (possibly very many db calls)
break;
$blockinstance = new BlockInstance(
$configdata = $blockinstance-
if (!empty(
foreach ($array as $duplicatefeed => $ids) {
foreach ($ids as $key => $id) {
if ($id == $configdata[
// not using the first instance id of this feed
$blockinstanc
}
}
}
}
step 4: delete the now orphaned feed id(s) rows
foreach ($array as $duplicatefeed => $ids) { externalfeed_ data} WHERE id = ? (possibly very many db calls)
foreach ($ids as $key => $id) {
if ($key != '0') {
DELETE FROM {blocktype_
}
}
}
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?