Foxy brown has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/370502 )
Change subject: Adding to the Article Reminder feature its delay mechanism
......................................................................
Adding to the Article Reminder feature its delay mechanism
Bug:T172541
Change-Id: I6e8ea4bc079f9bd66f6435c9549e43485379b95d
---
M Hooks.php
A db_patches/patch-add-echo_event-event_scheduled_timestamp.sql
M includes/model/Event.php
A maintenance/triggerSchedualedEvents.php
4 files changed, 113 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/02/370502/1
diff --git a/Hooks.php b/Hooks.php
index a195d5c..cf102c6 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -229,6 +229,7 @@
$updater->addExtensionIndex( 'echo_target_page',
'echo_target_page_page_event', "$dir/db_patches/patch-add-page_event-index.sql"
);
$updater->addExtensionIndex( 'echo_event',
'echo_event_page_id', "$dir/db_patches/patch-add-event_page_id-index.sql" );
$updater->dropExtensionIndex( 'echo_notification',
'user_event', "$dir/db_patches/patch-notification-pk.sql" );
+ $updater->addExtensionField( 'echo_event',
'event_scheduled_timestamp',
"$dir/db_patches/patch-add-echo_event-event_scheduled_timestamp.sql.sql" );
}
/**
diff --git a/db_patches/patch-add-echo_event-event_scheduled_timestamp.sql
b/db_patches/patch-add-echo_event-event_scheduled_timestamp.sql
new file mode 100644
index 0000000..c77ad33
--- /dev/null
+++ b/db_patches/patch-add-echo_event-event_scheduled_timestamp.sql
@@ -0,0 +1 @@
+ALTER TABLE /*_*/echo_event ADD event_scheduled_timestamp binary(14) null;
diff --git a/includes/model/Event.php b/includes/model/Event.php
index be8b092..68d1933 100644
--- a/includes/model/Event.php
+++ b/includes/model/Event.php
@@ -173,6 +173,27 @@
return $obj;
}
+
+ /**
+ * Creates a schedualed EchoEvent object
+ * @param $info array Named arguments:
+ * type (required): The event type;
+ * time (required): The timestamp for the delay;
+ * variant: A variant of the type;
+ * agent: The user who caused the event;
+ * title: The page on which the event was triggered;
+ * extra: Event-specific extra information (e.g. post content)
+ *
+ * @throws MWException
+ * @return EchoEvent|bool false if aborted via hook or Echo DB is
read-only
+ */
+ public static function createSchedualed( $info = [] ) {
+ if ( empty( $info['time'] ) ) {
+ throw new MWException( "'time' parameter is mandatory"
);
+ }
+ return EchoEvent::create( $info );
+ }
+
/**
* Convert the object's database property to array
* @return array
diff --git a/maintenance/triggerSchedualedEvents.php
b/maintenance/triggerSchedualedEvents.php
new file mode 100644
index 0000000..a256303
--- /dev/null
+++ b/maintenance/triggerSchedualedEvents.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * Trigger schedualed events from echo_event
+ *
+ * @ingroup Maintenance
+ */
+require_once getenv( 'MW_INSTALL_PATH' ) !== false
+ ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
+ : __DIR__ . '/../../../maintenance/Maintenance.php';
+
+/**
+ * Maintenance script that removes invalid notifications
+ *
+ * @ingroup Maintenance
+ */
+class RemoveInvalidNotification extends Maintenance {
+
+ protected $batchSize = 500;
+ protected $invalidEventType = [ 'article-linked' ];
+
+ public function __construct() {
+ $this->mDescription = "Triggers schedualed event from the
database.";
+ $this->requireExtension( 'Echo' );
+ }
+
+ public function execute() {
+ if ( !$this->invalidEventType ) {
+ $this->output( "There is nothing to process\n" );
+
+ return;
+ }
+
+ global $wgEchoCluster;
+
+ $dbw = MWEchoDbFactory::getDB( DB_MASTER );
+ $dbr = MWEchoDbFactory::getDB( DB_SLAVE );
+
+ $maxTime = new DateTime()->getTimestamp( TS_ISO_8601 );
+ $oneHour = new DateInterval( 'P1H' );
+ $minTime = $maxTime->sub( $oneHour )->getTimestamp( TS_ISO_8601
);
+
+ $count = $this->batchSize;
+
+ while ( $count == $this->batchSize ) {
+ $res = $dbr->select(
+ /* FROM */
+ [ 'echo_event' ],
+ /* SELECT */
+ [ 'event_id', 'event_scheduled_timestamp' ],
+ /* WHERE */
+ "event_scheduled_timestamp BETWEEN $minTime AND
$maxTime",
+ __METHOD__,
+ [
+ 'ORDER BY' =>
'event_scheduled_timestamp',
+ 'LIMIT' => $this->batchSize
+ ]
+ );
+
+ $event = [];
+ $count = 0;
+ foreach ( $res as $row ) {
+ if ( !in_array( $row->event_id, $event ) ) {
+ $event[] = $row->event_id;
+ }
+ $count++;
+ };
+
+ if ( $event ) {
+ $this->beginTransaction( $dbw, __METHOD__ );
+
+ $dbw->delete(
+ 'echo_event',
+ [ 'event_id' => $event ],
+ __METHOD__
+ );
+
+ $this->commitTransaction( $dbw, __METHOD__ );
+
+ $this->output( "processing " . count( $event )
. " schedualed events\n" );
+ wfWaitForSlaves( false, false, $wgEchoCluster );
+ }
+
+ // Cleanup is not necessary for
+ // 1. echo_email_batch, invalid notification is removed
during the cron
+ }
+ }
+}
+
+$maintClass = 'TriggerSchedualedEvents'; // Tells it to run the class
+require_once RUN_MAINTENANCE_IF_MAIN;
--
To view, visit https://gerrit.wikimedia.org/r/370502
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e8ea4bc079f9bd66f6435c9549e43485379b95d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Foxy brown <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits