Matthias Mullie has uploaded a new change for review.

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


Change subject: Fix auto-archive script
......................................................................

Fix auto-archive script

Auto-archive maintenance script (archiveFeedback.php) currently fails with an
exception thrown by ArticleFeedbackv5Model::validate()
This function checks some of the data being saved and, if incorrect, throws an
exception. One of these checks if looking if the page id is valid.
Apperently, for some old feedback, the article can't be fetched (probably
deleted). While it is great that, before inserting, this data is validated, it
is not so great in this usecase, where it renders us unable to update the entry
(unless we were to assign it to a new page, or delete it)

I've added a switch to make this validation optional. When inserting data, we
should definitely validate, but flagging feedback shouldn't be hindered.

Change-Id: If0d6962aa38e9a93e0cec37db2b0405683295f4a
---
M ArticleFeedbackv5.flagging.php
M ArticleFeedbackv5.model.php
M data/DataModel.php
M maintenance/archiveFeedback.php
4 files changed, 18 insertions(+), 10 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticleFeedbackv5 
refs/changes/54/73954/1

diff --git a/ArticleFeedbackv5.flagging.php b/ArticleFeedbackv5.flagging.php
index ccc9940..30a1cc3 100644
--- a/ArticleFeedbackv5.flagging.php
+++ b/ArticleFeedbackv5.flagging.php
@@ -142,7 +142,7 @@
                }
 
                // update feedback entry for real
-               $this->feedback->update();
+               $this->feedback->update( false );
 
                wfProfileOut( __METHOD__ . "-{$flag}" );
 
diff --git a/ArticleFeedbackv5.model.php b/ArticleFeedbackv5.model.php
index 631f16d..5bc89a4 100644
--- a/ArticleFeedbackv5.model.php
+++ b/ArticleFeedbackv5.model.php
@@ -468,10 +468,11 @@
        /**
         * Insert entry into the DB (& cache)
         *
+        * @param bool[optional] $validate True if data should be validated
         * @return DataModel
         * @throw MWException
         */
-       public function insert() {
+       public function insert( $validate = true ) {
                // if no creation timestamp is entered yet, fill it out
                if ( $this->aft_timestamp === null ) {
                        $this->aft_timestamp = wfTimestampNow();
@@ -483,23 +484,24 @@
                $this->aft_archive_date = $this->getArchiveDate();
                $this->updateCountFound();
 
-               return parent::insert();
+               return parent::insert( $validate );
        }
 
        /**
         * Update entry in the DB (& cache)
         *
+        * @param bool[optional] $validate True if data should be validated
         * @return DataModel
         * @throw MWException
         */
-       public function update() {
+       public function update( $validate = true ) {
                $this->aft_net_helpful = $this->aft_helpful - 
$this->aft_unhelpful;
                $this->aft_relevance_score = $this->getRelevanceScore();
                $this->aft_has_comment = (bool) $this->aft_comment;
                $this->aft_archive_date = $this->getArchiveDate();
                $this->updateCountFound();
 
-               return parent::update();
+               return parent::update( $validate );
        }
 
        /**
diff --git a/data/DataModel.php b/data/DataModel.php
index 9f4f412..3c1b619 100644
--- a/data/DataModel.php
+++ b/data/DataModel.php
@@ -375,17 +375,20 @@
        /**
         * Insert entry.
         *
+        * @param bool[optional] $validate True if data should be validated
         * @return DataModel
         * @throw MWException
         */
-       public function insert() {
+       public function insert( $validate = true ) {
                // claim unique id for this entry
                if ( $this->{static::getIdColumn()} === null ) {
                        $this->{static::getIdColumn()} = $this->generateId();
                }
 
                // validate properties before saving them
-               $this->validate();
+               if ( $validate ) {
+                       $this->validate();
+               }
 
                // insert into DB
                static::getBackend()->insert( $this );
@@ -402,16 +405,19 @@
        /**
         * Update entry.
         *
+        * @param bool[optional] $validate True if data should be validated
         * @return DataModel
         * @throw MWException
         */
-       public function update() {
+       public function update( $validate = true ) {
                if ( $this->{static::getIdColumn()} === null ) {
                        throw new MWException( "Entry has no unique id yet - 
did you intend to insert rather than update?" );
                }
 
                // validate properties before saving them
-               $this->validate();
+               if ( $validate ) {
+                       $this->validate();
+               }
 
                // before updating in db, let's re-evaluate all list conditions 
& sorts
                $old = static::getBackend()->evaluateConditions( $this );
diff --git a/maintenance/archiveFeedback.php b/maintenance/archiveFeedback.php
index 3ff14f5..2c5f36a 100644
--- a/maintenance/archiveFeedback.php
+++ b/maintenance/archiveFeedback.php
@@ -92,7 +92,7 @@
                                        } else {
                                                // if we could not flag, unmark 
as archive_schedule
                                                $feedback->aft_archive_date = 
null;
-                                               $feedback->update();
+                                               $feedback->update( false );
                                        }
 
                                        $break = false;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If0d6962aa38e9a93e0cec37db2b0405683295f4a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticleFeedbackv5
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

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

Reply via email to