mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
Merge MWDbEchoEmailBundler into MWEchoEmailBundler, remove abstraction layer
Change-Id: Ifc05f1d03d1dde79d5c788ee7417ed0cec43155f
This commit is contained in:
parent
24cd62e322
commit
07da9c2e41
|
@ -87,7 +87,6 @@ $wgAutoloadClasses += array(
|
|||
'EchoUserNotificationGatewayTest' => __DIR__ . '/tests/phpunit/includes/gateway/UserNotificationGatewayTest.php',
|
||||
'EchoUserRightsFormatter' => __DIR__ . '/includes/formatters/UserRightsFormatter.php',
|
||||
'FilteredSequentialIteratorTest' => __DIR__ . '/tests/phpunit/includes/iterator/FilteredSequentialIteratorTest.php',
|
||||
'MWDbEchoEmailBundler' => __DIR__ . '/includes/DbEmailBundler.php',
|
||||
'MWEchoDbFactory' => __DIR__ . '/includes/EchoDbFactory.php',
|
||||
'MWEchoDbFactoryTest' => __DIR__ . '/tests/phpunit/includes/EchoDbFactoryTest.php',
|
||||
'MWEchoEmailBatch' => __DIR__ . '/includes/EmailBatch.php',
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Email Bundling for database storage
|
||||
*/
|
||||
class MWDbEchoEmailBundler extends MWEchoEmailBundler {
|
||||
|
||||
/**
|
||||
* Retrieve the base event for email bundling, the one with the largest eeb_id
|
||||
* @return bool
|
||||
*/
|
||||
protected function retrieveBaseEvent() {
|
||||
$dbr = MWEchoDbFactory::getDB( DB_SLAVE );
|
||||
$res = $dbr->selectRow(
|
||||
array( 'echo_email_batch' ),
|
||||
array( 'eeb_event_id' ),
|
||||
array(
|
||||
'eeb_user_id' => $this->mUser->getId(),
|
||||
'eeb_event_hash' => $this->bundleHash
|
||||
),
|
||||
__METHOD__,
|
||||
array( 'ORDER BY' => 'eeb_event_priority DESC, eeb_id DESC', 'LIMIT' => 1 )
|
||||
);
|
||||
if ( !$res ) {
|
||||
return false;
|
||||
}
|
||||
$this->baseEvent = EchoEvent::newFromId( $res->eeb_event_id );
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear processed events from the queue
|
||||
*/
|
||||
protected function clearProcessedEvent() {
|
||||
if ( !$this->baseEvent ) {
|
||||
return;
|
||||
}
|
||||
$conds = array( 'eeb_user_id' => $this->mUser->getId(), 'eeb_event_hash' => $this->bundleHash );
|
||||
|
||||
$conds[] = 'eeb_event_id <= ' . intval( $this->baseEvent->getId() );
|
||||
|
||||
$dbw = MWEchoDbFactory::getDB( DB_MASTER );
|
||||
$dbw->delete(
|
||||
'echo_email_batch',
|
||||
$conds,
|
||||
__METHOD__,
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
* 2. a job is popped off the queue which calls self::processBundleEmail()
|
||||
*
|
||||
*/
|
||||
abstract class MWEchoEmailBundler {
|
||||
class MWEchoEmailBundler {
|
||||
|
||||
/**
|
||||
* @var User
|
||||
|
@ -67,7 +67,7 @@ abstract class MWEchoEmailBundler {
|
|||
if ( !$hash || !preg_match( '/^[a-f0-9]{32}$/', $hash ) ) {
|
||||
return false;
|
||||
}
|
||||
return new MWDbEchoEmailBundler( $user, $hash );
|
||||
return new self( $user, $hash );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,10 +167,27 @@ abstract class MWEchoEmailBundler {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve the base event for email bundling
|
||||
* Retrieve the base event for email bundling, the one with the largest eeb_id
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function retrieveBaseEvent();
|
||||
protected function retrieveBaseEvent() {
|
||||
$dbr = MWEchoDbFactory::getDB( DB_SLAVE );
|
||||
$res = $dbr->selectRow(
|
||||
array( 'echo_email_batch' ),
|
||||
array( 'eeb_event_id' ),
|
||||
array(
|
||||
'eeb_user_id' => $this->mUser->getId(),
|
||||
'eeb_event_hash' => $this->bundleHash
|
||||
),
|
||||
__METHOD__,
|
||||
array( 'ORDER BY' => 'eeb_event_priority DESC, eeb_id DESC', 'LIMIT' => 1 )
|
||||
);
|
||||
if ( !$res ) {
|
||||
return false;
|
||||
}
|
||||
$this->baseEvent = EchoEvent::newFromId( $res->eeb_event_id );
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push the latest bundle data to the queue
|
||||
|
@ -267,6 +284,20 @@ abstract class MWEchoEmailBundler {
|
|||
/**
|
||||
* clear processed event in the queue
|
||||
*/
|
||||
abstract protected function clearProcessedEvent();
|
||||
protected function clearProcessedEvent() {
|
||||
if ( !$this->baseEvent ) {
|
||||
return;
|
||||
}
|
||||
$conds = array( 'eeb_user_id' => $this->mUser->getId(), 'eeb_event_hash' => $this->bundleHash );
|
||||
|
||||
$conds[] = 'eeb_event_id <= ' . intval( $this->baseEvent->getId() );
|
||||
|
||||
$dbw = MWEchoDbFactory::getDB( DB_MASTER );
|
||||
$dbw->delete(
|
||||
'echo_email_batch',
|
||||
$conds,
|
||||
__METHOD__,
|
||||
array()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue