From 6778b932cad74239654fdfad0b1083565b9f6e18 Mon Sep 17 00:00:00 2001 From: aude Date: Wed, 18 Sep 2013 22:28:14 +0200 Subject: [PATCH] Reduce complexity of SiteSQLStore saveSites method split code that generates an ORMRow from a Site object Change-Id: Ie1f7ed834a33befb43536355ad2b9b98a13d4c79 --- includes/site/SiteSQLStore.php | 52 ++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/includes/site/SiteSQLStore.php b/includes/site/SiteSQLStore.php index 412380550f..11141e07df 100644 --- a/includes/site/SiteSQLStore.php +++ b/includes/site/SiteSQLStore.php @@ -188,6 +188,39 @@ class SiteSQLStore implements SiteStore { return $site; } + /** + * Get a new ORMRow from a Site object + * + * @since 1.22 + * + * @param Site + * + * @return ORMRow + */ + protected function getRowFromSite( Site $site ) { + $fields = array( + // Site data + 'global_key' => $site->getGlobalId(), // TODO: check not null + 'type' => $site->getType(), + 'group' => $site->getGroup(), + 'source' => $site->getSource(), + 'language' => $site->getLanguageCode() === null ? '' : $site->getLanguageCode(), + 'protocol' => $site->getProtocol(), + 'domain' => strrev( $site->getDomain() ) . '.', + 'data' => $site->getExtraData(), + + // Site config + 'forward' => $site->shouldForward(), + 'config' => $site->getExtraConfig(), + ); + + if ( $site->getInternalId() !== null ) { + $fields['id'] = $site->getInternalId(); + } + + return new ORMRow( $this->sitesTable, $fields ); + } + /** * Fetches the site from the database and loads them into the sites field. * @@ -291,28 +324,11 @@ class SiteSQLStore implements SiteStore { $localIds = array(); foreach ( $sites as $site ) { - $fields = array( - // Site data - 'global_key' => $site->getGlobalId(), // TODO: check not null - 'type' => $site->getType(), - 'group' => $site->getGroup(), - 'source' => $site->getSource(), - 'language' => $site->getLanguageCode() === null ? '' : $site->getLanguageCode(), - 'protocol' => $site->getProtocol(), - 'domain' => strrev( $site->getDomain() ) . '.', - 'data' => $site->getExtraData(), - - // Site config - 'forward' => $site->shouldForward(), - 'config' => $site->getExtraConfig(), - ); - if ( $site->getInternalId() !== null ) { - $fields['id'] = $site->getInternalId(); $internalIds[] = $site->getInternalId(); } - $siteRow = new ORMRow( $this->sitesTable, $fields ); + $siteRow = $this->getRowFromSite( $site ); $success = $siteRow->save( __METHOD__ ) && $success; foreach ( $site->getLocalIds() as $idType => $ids ) { -- 2.20.1