Yaron Koren has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/278585

Change subject: Fixes for when there is no _pageData table
......................................................................

Fixes for when there is no _pageData table

Change-Id: Icbfea5fec6977808877717fb491e933d18ffa269
---
M Cargo.hooks.php
M CargoPageData.php
2 files changed, 58 insertions(+), 52 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/85/278585/1

diff --git a/Cargo.hooks.php b/Cargo.hooks.php
index dd9a275..ca28bc9 100644
--- a/Cargo.hooks.php
+++ b/Cargo.hooks.php
@@ -137,7 +137,10 @@
                        // Now, delete from the "main" table.
                        $cdb->delete( $curMainTable, array( '_pageID' => 
$pageID ) );
                }
-               $cdb->delete( '_pageData', array( '_pageID' => $pageID ) );
+               $res3 = $dbw->select( 'cargo_tables', 'field_tables', array( 
'main_table' => '_pageData' ) );
+               if ( $dbw->numRows( $res3 ) > 0 ) {
+                       $cdb->delete( '_pageData', array( '_pageID' => $pageID 
) );
+               }
 
                // Finally, delete from cargo_pages.
                $dbw->delete( 'cargo_pages', array( 'page_id' => $pageID ) );
diff --git a/CargoPageData.php b/CargoPageData.php
index 04b4227..07661cf 100644
--- a/CargoPageData.php
+++ b/CargoPageData.php
@@ -53,62 +53,65 @@
                        return;
                }
 
-                $wikiPage = WikiPage::factory( $title );
-                $pageDataValues = array();
-
-                if ( in_array( CARGO_STORE_CREATION_DATE, 
$wgCargoPageDataColumns ) ) {
-                        $firstRevision = $title->getFirstRevision();
-                        if ( $firstRevision == null ) {
-                                // This can sometimes happen.
-                                $pageDataValues['_creationDate'] = null;
-                        } else {
-                                $pageDataValues['_creationDate'] = 
$firstRevision->getTimestamp();
-                        }
-                }
-                if ( in_array( CARGO_STORE_MODIFICATION_DATE, 
$wgCargoPageDataColumns ) ) {
-                        $pageDataValues['_modificationDate'] = 
$wikiPage->getTimestamp();
-                }
-                if ( in_array( CARGO_STORE_CREATOR, $wgCargoPageDataColumns ) 
) {
-                        $pageDataValues['_creator'] = $wikiPage->getCreator();
-                }
-                if ( in_array( CARGO_STORE_FULL_TEXT, $wgCargoPageDataColumns 
) ) {
-                        $article = new Article( $title );
-                        $pageDataValues['_fullText'] = $article->getContent();
-                }
-                if ( in_array( CARGO_STORE_CATEGORIES, $wgCargoPageDataColumns 
) ) {
-                        $pageCategories = array();
-                       $dbr = wfGetDB( DB_SLAVE );
-                        $res = $dbr->select(
-                                'categorylinks',
-                                'cl_to',
-                                array( 'cl_from' => $title->getArticleID() ),
-                                __METHOD__
-                        );
-                        foreach ( $res as $row ) {
-                                $pageCategories[] = $row->cl_to;
-                        }
-
-                        $pageCategoriesString = implode( '|', $pageCategories 
);
-                        $pageDataValues['_categories'] = $pageCategoriesString;
+               // If there is no _pageData table, getTableSchemas() will
+               // throw an error.
+               try {
+                       $tableSchemas = CargoUtils::getTableSchemas( array( 
'_pageData' ) );
+               } catch ( MWException $e ) {
+                       return;
                }
-                if ( in_array( CARGO_STORE_NUM_REVISIONS, 
$wgCargoPageDataColumns ) ) {
+
+               $wikiPage = WikiPage::factory( $title );
+               $pageDataValues = array();
+
+               if ( in_array( CARGO_STORE_CREATION_DATE, 
$wgCargoPageDataColumns ) ) {
+                       $firstRevision = $title->getFirstRevision();
+                       if ( $firstRevision == null ) {
+                               // This can sometimes happen.
+                               $pageDataValues['_creationDate'] = null;
+                       } else {
+                               $pageDataValues['_creationDate'] = 
$firstRevision->getTimestamp();
+                       }
+               }
+               if ( in_array( CARGO_STORE_MODIFICATION_DATE, 
$wgCargoPageDataColumns ) ) {
+                       $pageDataValues['_modificationDate'] = 
$wikiPage->getTimestamp();
+               }
+               if ( in_array( CARGO_STORE_CREATOR, $wgCargoPageDataColumns ) ) 
{
+                       $pageDataValues['_creator'] = $wikiPage->getCreator();
+               }
+               if ( in_array( CARGO_STORE_FULL_TEXT, $wgCargoPageDataColumns ) 
) {
+                       $article = new Article( $title );
+                       $pageDataValues['_fullText'] = $article->getContent();
+               }
+               if ( in_array( CARGO_STORE_CATEGORIES, $wgCargoPageDataColumns 
) ) {
+                       $pageCategories = array();
                        $dbr = wfGetDB( DB_SLAVE );
-                        $res = $dbr->select(
-                                'revision',
-                                'COUNT(*)',
-                                array( 'rev_page' => $title->getArticleID() ),
-                                __METHOD__
-                        );
+                       $res = $dbr->select(
+                               'categorylinks',
+                               'cl_to',
+                               array( 'cl_from' => $title->getArticleID() ),
+                               __METHOD__
+                       );
+                       foreach ( $res as $row ) {
+                               $pageCategories[] = $row->cl_to;
+                       }
+
+                       $pageCategoriesString = implode( '|', $pageCategories );
+                       $pageDataValues['_categories'] = $pageCategoriesString;
+               }
+               if ( in_array( CARGO_STORE_NUM_REVISIONS, 
$wgCargoPageDataColumns ) ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $res = $dbr->select(
+                               'revision',
+                               'COUNT(*)',
+                               array( 'rev_page' => $title->getArticleID() ),
+                               __METHOD__
+                       );
                        $row = $dbr->fetchRow( $res );
                        $pageDataValues['_numRevisions'] = $row[0];
-                }
+               }
 
-                $tableSchemas = CargoUtils::getTableSchemas( array( 
'_pageData' ) );
-                if ( !array_key_exists( '_pageData', $tableSchemas ) ) {
-                        return false;
-                }
-
-                CargoStore::storeAllData( $title, '_pageData', 
$pageDataValues, $tableSchemas['_pageData'] );
+               CargoStore::storeAllData( $title, '_pageData', $pageDataValues, 
$tableSchemas['_pageData'] );
        }
 
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/278585
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icbfea5fec6977808877717fb491e933d18ffa269
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to