jenkins-bot has submitted this change and it was merged. Change subject: Fixes in TreeRepository ......................................................................
Fixes in TreeRepository insertSelect will not work in unit tests, since they're in a temp table Change-Id: I2af85eaad24bf45926dbe2505afdfca82ab28854 --- M includes/Repository/TreeRepository.php 1 file changed, 53 insertions(+), 17 deletions(-) Approvals: EBernhardson: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/Repository/TreeRepository.php b/includes/Repository/TreeRepository.php index 9bb47fa..c0b2cde 100644 --- a/includes/Repository/TreeRepository.php +++ b/includes/Repository/TreeRepository.php @@ -91,21 +91,57 @@ ), __METHOD__ ); + if ( $res && $ancestor !== null ) { - $res = $dbw->insertSelect( - $this->tableName, - $this->tableName, - array( - 'tree_descendant_id' => $dbw->addQuotes( $descendant->getBinary() ), - 'tree_ancestor_id' => 'tree_ancestor_id', - 'tree_depth' => 'tree_depth + 1', - ), - array( - 'tree_descendant_id' => $ancestor->getBinary(), - ), - __METHOD__ - ); + try { + $res = $dbw->insertSelect( + $this->tableName, + $this->tableName, + array( + 'tree_descendant_id' => $dbw->addQuotes( $descendant->getBinary() ), + 'tree_ancestor_id' => 'tree_ancestor_id', + 'tree_depth' => 'tree_depth + 1', + ), + array( + 'tree_descendant_id' => $ancestor->getBinary(), + ), + __METHOD__ + ); + } catch( \DBQueryError $e ) { + /* + * insertSelect won't work on temporary tables (as used for MW + * unit tests), because it refers to the same table twice, in + * one query. + * In this case, we'll do a separate select & insert. + * + * @see https://dev.mysql.com/doc/refman/5.0/en/temporary-table-problems.html + * @see http://dba.stackexchange.com/questions/45270/mysql-error-1137-hy000-at-line-9-cant-reopen-table-temp-table + */ + if ( $dbw->lastErrno() === 1137 ) { + // @todo: needs to be done for ALL depths, not just one + $rows = $dbw->select( + $this->tableName, + array( 'tree_depth' ), + array( 'tree_descendant_id' => $ancestor->getBinary() ), + __METHOD__ + ); + + $res = true; + foreach ( $rows as $row ) { + $res &= $dbw->insert( + $this->tableName, + array( + 'tree_descendant_id' => $descendant->getBinary(), + 'tree_ancestor_id' => $ancestor->getBinary(), + 'tree_depth' => $row->tree_depth + 1, + ), + __METHOD__ + ); + } + } + } } + if ( !$res ) { $this->cache->delete( $parentKey ); $this->cache->delete( $pathKey ); @@ -163,7 +199,7 @@ if ( isset( $cacheResult[$cacheKeys[$descendant->getAlphadecimal()]] ) ) { $cacheValues[$descendant->getAlphadecimal()] = $cacheResult[$cacheKeys[$descendant->getAlphadecimal()]]; } else { - // This doubles as a way to convert binary UUIDs to hex + // This doubles as a way to convert binary UUIDs to alphanumeric $missingValues[$descendant->getBinary()] = $descendant->getAlphadecimal(); } } @@ -244,12 +280,12 @@ // To simplify caching we will work through the root path instead // of caching our own value $path = $this->findRootPath( $descendant ); - $root = array_shift( $path ); - - if ( ! $root ) { + if ( !$path ) { throw new DataModelException( $descendant->getAlphadecimal().' has no root post. Probably is a root post.', 'process-data' ); } + $root = array_shift( $path ); + return $root; } -- To view, visit https://gerrit.wikimedia.org/r/116083 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2af85eaad24bf45926dbe2505afdfca82ab28854 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits