Yaron Koren has submitted this change and it was merged.

Change subject:  Add 'files' helper tables
......................................................................


Add 'files' helper tables

Change-Id: Id0726b77f0a8d3af37edb88dad0f51298f080a13
---
M Cargo.hooks.php
M CargoUtils.php
M parserfunctions/CargoStore.php
3 files changed, 65 insertions(+), 0 deletions(-)

Approvals:
  Yaron Koren: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Cargo.hooks.php b/Cargo.hooks.php
index ccb9fa8..a6dd63a 100755
--- a/Cargo.hooks.php
+++ b/Cargo.hooks.php
@@ -138,6 +138,12 @@
                                );
                        }
 
+                       // Delete from the "files" helper table, if it exists.
+                       $curFilesTable = $curMainTable . '___files';
+                       if ( $cdb->tableExists( $curFilesTable ) ) {
+                               $cdb->delete( $curFilesTable, $cdbPageIDCheck );
+                       }
+
                        // Now, delete from the "main" table.
                        $cdb->delete( $curMainTable, $cdbPageIDCheck );
                }
diff --git a/CargoUtils.php b/CargoUtils.php
index 38b5a27..a3eaa83 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -552,6 +552,7 @@
                        $cdb->addIdentifierQuotes( '_pageID' ) . " 
$intTypeString NOT NULL";
 
                $containsSearchTextType = false;
+               $containsFileType = false;
                foreach ( $tableSchema->mFieldDescriptions as $fieldName => 
$fieldDescription ) {
                        $size = $fieldDescription->mSize;
                        $isList = $fieldDescription->mIsList;
@@ -584,6 +585,8 @@
                        } elseif ( $fieldType == 'Searchtext' ) {
                                $createSQL .= ", FULLTEXT KEY $fieldName (" . 
$cdb->addIdentifierQuotes( $fieldName ) . ')';
                                $containsSearchTextType = true;
+                       } elseif ( $fieldType == 'File' ) {
+                               $containsFileType = true;
                        }
                }
                $createSQL .= ' )';
@@ -648,6 +651,22 @@
                        $fieldTableNames[] = $tableName . '__' . $fieldName;
                }
 
+               // And create a helper table holding all the files stored in
+               // this table, if there are any.
+               if ( $containsFileType ) {
+                       $fileTableName = $tableName . '___files';
+                       $cdb->dropTable( $fileTableName );
+                       $fieldType = $fieldDescription->mType;
+                       $createSQL = "CREATE TABLE " .
+                               $cdb->tableName( $fileTableName ) . ' ( ' .
+                               $cdb->addIdentifierQuotes( '_pageName' ) . " 
$stringTypeString, " .
+                               $cdb->addIdentifierQuotes( '_pageID' ) . " 
$intTypeString, " .
+                               $cdb->addIdentifierQuotes( '_fieldName' ) . " 
$stringTypeString, " .
+                               $cdb->addIdentifierQuotes( '_fileName' ) . " 
$stringTypeString";
+                       $createSQL .= ' )';
+                       $cdb->query( $createSQL );
+               }
+
                // Necessary in some cases.
                $cdb->close();
 
diff --git a/parserfunctions/CargoStore.php b/parserfunctions/CargoStore.php
index d92fb9b..fbebddf 100644
--- a/parserfunctions/CargoStore.php
+++ b/parserfunctions/CargoStore.php
@@ -327,6 +327,46 @@
                // Insert the current data into the main table.
                CargoUtils::escapedInsert( $cdb, $tableName, $tableFieldValues 
);
 
+               // Also insert the names of any "attached" files into the
+               // "files" helper table.
+               $fileTableName = $tableName . '___files';
+               foreach ( $tableSchema->mFieldDescriptions as $fieldName => 
$fieldDescription ) {
+                       $fieldType = $fieldDescription->mType;
+                       if ( $fieldType != 'File' ) {
+                               continue;
+                       }
+                       if ( $fieldDescription->mIsList ) {
+                               $delimiter = $fieldDescription->getDelimiter();
+                               $individualValues = explode( $delimiter, 
$tableFieldValues[$fieldName . '__full'] );
+                               foreach ( $individualValues as $individualValue 
) {
+                                       $individualValue = trim( 
$individualValue );
+                                       // Ignore blank values.
+                                       if ( $individualValue == '' ) {
+                                               continue;
+                                       }
+                                       $fieldValues = array(
+                                               '_pageName' => $pageName,
+                                               '_pageID' => $pageID,
+                                               '_fieldName' => $fieldName,
+                                               '_fileName' => $individualValue
+                                       );
+                                       CargoUtils::escapedInsert( $cdb, 
$fileTableName, $fieldValues );
+                               }
+                       } else {
+                               $fileName = $tableFieldValues[$fieldName];
+                               if ( $fileName == '' ) {
+                                       continue;
+                               }
+                               $fieldValues = array(
+                                       '_pageName' => $pageName,
+                                       '_pageID' => $pageID,
+                                       '_fieldName' => $fieldName,
+                                       '_fileName' => $fileName
+                               );
+                               CargoUtils::escapedInsert( $cdb, 
$fileTableName, $fieldValues );
+                       }
+               }
+
                // This close() call, for some reason, is necessary for the
                // subsequent SQL to be called correctly, when jobs are run
                // in the standard way.

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id0726b77f0a8d3af37edb88dad0f51298f080a13
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <yaro...@gmail.com>
Gerrit-Reviewer: Yaron Koren <yaro...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to