Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Commit

Permalink
Added events to the other sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragonrun1 committed Dec 22, 2014
1 parent c43d799 commit 3f0e8d1
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 130 deletions.
20 changes: 8 additions & 12 deletions lib/Database/AbstractCommonEveApi.php
Expand Up @@ -49,7 +49,6 @@
use Yapeal\Event\EveApiEvent;
use Yapeal\Event\YapealEventDispatcherInterface;
use Yapeal\Xml\EveApiPreserverInterface;
use Yapeal\Xml\EveApiReadInterface;
use Yapeal\Xml\EveApiReadWriteInterface;
use Yapeal\Xml\EveApiRetrieverInterface;

Expand Down Expand Up @@ -114,8 +113,6 @@ public function autoMagic(
) {
return;
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_PRESERVER, $data);
if (!$this->oneShot($data, $retrievers, $preservers, $interval)) {
return;
}
Expand Down Expand Up @@ -144,6 +141,8 @@ public function oneShot(
if (!$this->gotApiLock($data)) {
return false;
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_RETRIEVE, $data);
$retrievers->retrieveEveApi($data);
if ($data->getEveApiXml() === false) {
$mess = sprintf(
Expand Down Expand Up @@ -172,11 +171,8 @@ public function oneShot(
$preservers->preserveEveApi($data);
return false;
}
$event = $this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_PRESERVER, $data);
if ($event->isChanged()) {
$data = $event->getData();
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_PRESERVER, $data);
$preservers->preserveEveApi($data);
// No need / way to preserve XML errors to the database with normal
// preserveTo*.
Expand Down Expand Up @@ -274,12 +270,12 @@ protected function getXslName($apiName, $sectionName)
return $xslName;
}
/**
* @param EveApiReadInterface $data
* @param EveApiReadWriteInterface $data
*
* @throws LogicException
* @return bool
*/
protected function gotApiLock(EveApiReadInterface &$data)
protected function gotApiLock(EveApiReadWriteInterface &$data)
{
$sql = $this->getCsq()
->getApiLock($data->getHash());
Expand Down Expand Up @@ -356,12 +352,12 @@ protected function isEveApiXmlError(
return true;
}
/**
* @param EveApiReadInterface $data
* @param EveApiReadWriteInterface $data
*
* @throws LogicException
* @return bool
*/
protected function isInvalid(EveApiReadInterface &$data)
protected function isInvalid(EveApiReadWriteInterface &$data)
{
$this->getLogger()
->debug('Started XSD validating');
Expand Down
48 changes: 12 additions & 36 deletions lib/Database/Char/AbstractCharSection.php
Expand Up @@ -67,11 +67,8 @@ public function autoMagic(
$interval
)
{
$event = $this->getYed()
->dispatchEveApiEvent(EveApiEvent::START, $data);
if ($event->isChanged()) {
$data = $event->getData();
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::START, $data);
$this->getLogger()
->debug(
sprintf(
Expand Down Expand Up @@ -100,14 +97,6 @@ public function autoMagic(
$data->setEveApiArguments($char)
->setEveApiXml();
$untilInterval = $interval;
$event = $this->getYed()
->dispatchEveApiEvent(
EveApiEvent::PRE_PRESERVER,
$data
);
if ($event->isChanged()) {
$data = $event->getData();
}
if (!$this->oneShot(
$data,
$retrievers,
Expand All @@ -117,14 +106,8 @@ public function autoMagic(
) {
continue;
}
$event = $this->getYed()
->dispatchEveApiEvent(
EveApiEvent::POST_PRESERVER,
$data
);
if ($event->isChanged()) {
$data = $event->getData();
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::POST_PRESERVER, $data);
$this->updateCachedUntil(
$data->getEveApiXml(),
$untilInterval,
Expand Down Expand Up @@ -154,6 +137,8 @@ public function oneShot(
return false;
}
$charID = $data->getEveApiArgument('characterID');
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_RETRIEVE, $data);
$retrievers->retrieveEveApi($data);
if ($data->getEveApiXml() === false) {
$mess = sprintf(
Expand All @@ -166,17 +151,11 @@ public function oneShot(
->notice($mess);
return false;
}
$event = $this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_TRANSFORM, $data);
if ($event->isChanged()) {
$data = $event->getData();
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_TRANSFORM, $data);
$this->xsltTransform($data);
$event = $this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_VALIDATE, $data);
if ($event->isChanged()) {
$data = $event->getData();
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_VALIDATE, $data);
if ($this->isInvalid($data)) {
$mess = sprintf(
'The data retrieved from Eve API %1$s/%2$s for %3$s is invalid',
Expand All @@ -190,11 +169,8 @@ public function oneShot(
$preservers->preserveEveApi($data);
return false;
}
$event = $this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_PRESERVER, $data);
if ($event->isChanged()) {
$data = $event->getData();
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_PRESERVER, $data);
$preservers->preserveEveApi($data);
// No need / way to preserve XML errors to the database with normal
// preserve.
Expand Down
10 changes: 6 additions & 4 deletions lib/Database/Char/IndustryJobs.php
Expand Up @@ -64,12 +64,14 @@ public function autoMagic(
/**
* Update Industry Jobs History
*/
$class = new IndustryJobsHistory(
(
new IndustryJobsHistory(
$this->getPdo(),
$this->getLogger(),
$this->getCsq()
);
$class->autoMagic($data, $retrievers, $preservers, $interval);
$this->getCsq(),
$this->getYed()
)
)->autoMagic($data, $retrievers, $preservers, $interval);
parent::autoMagic($data, $retrievers, $preservers, $interval);
}
/**
Expand Down
24 changes: 16 additions & 8 deletions lib/Database/Char/MailBodies.php
Expand Up @@ -40,6 +40,7 @@
use SimpleXMLIterator;
use Yapeal\Database\AttributesDatabasePreserverTrait;
use Yapeal\Database\EveApiNameTrait;
use Yapeal\Event\EveApiEvent;
use Yapeal\Xml\EveApiPreserverInterface;
use Yapeal\Xml\EveApiReadWriteInterface;
use Yapeal\Xml\EveApiRetrieverInterface;
Expand All @@ -65,6 +66,8 @@ public function autoMagic(
$interval
)
{
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::START, $data);
$this->getLogger()
->debug(
sprintf(
Expand All @@ -76,12 +79,13 @@ public function autoMagic(
/**
* Update MailMessages List
*/
$class = new MailMessages(
(
new MailMessages(
$this->getPdo(),
$this->getLogger(),
$this->getCsq()
);
$class->autoMagic($data, $retrievers, $preservers, $interval);
$this->getCsq(), $this->getYed()
)
)->autoMagic($data, $retrievers, $preservers, $interval);
$active = $this->getActiveCharacters();
if (empty($active)) {
$this->getLogger()
Expand Down Expand Up @@ -110,14 +114,14 @@ public function autoMagic(
$mailIDs = array_chunk($mailIDs, 1000);
$untilInterval = $interval;
foreach ($mailIDs as $mailGroup) {
$mailIDs = [];
$mails = [];
foreach ($mailGroup as $mail) {
$mailIDs[] = $mail[0];
$mails[] = $mail[0];
}
$mess = 'Mail IDs = ' . implode(',', $mailIDs);
$mess = 'Mails = ' . implode(',', $mails);
$this->getLogger()
->debug($mess);
$char['ids'] = implode(',', $mailIDs);
$char['ids'] = implode(',', $mails);
$data->setEveApiArguments($char)
->setEveApiXml();
$untilInterval = $interval;
Expand All @@ -130,6 +134,8 @@ public function autoMagic(
) {
continue 2;
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::POST_PRESERVER, $data);
if ($untilInterval > $interval) {
$untilInterval = $interval;
}
Expand All @@ -143,6 +149,8 @@ public function autoMagic(
$charID
);
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::DONE, $data);
}
/**
* @param string $ownerID
Expand Down
18 changes: 15 additions & 3 deletions lib/Database/Corp/AbstractCorpSection.php
Expand Up @@ -39,6 +39,7 @@
use PDOException;
use Yapeal\Database\AbstractCommonEveApi;
use Yapeal\Database\EveSectionNameTrait;
use Yapeal\Event\EveApiEvent;
use Yapeal\Xml\EveApiPreserverInterface;
use Yapeal\Xml\EveApiReadWriteInterface;
use Yapeal\Xml\EveApiRetrieverInterface;
Expand All @@ -64,6 +65,8 @@ public function autoMagic(
$interval
)
{
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::START, $data);
$this->getLogger()
->debug(
sprintf(
Expand Down Expand Up @@ -101,12 +104,16 @@ public function autoMagic(
) {
continue;
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::POST_PRESERVER, $data);
$this->updateCachedUntil(
$data->getEveApiXml(),
$untilInterval,
$corp['corporationID']
);
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::DONE, $data);
}
/**
* @param EveApiReadWriteInterface $data
Expand All @@ -129,9 +136,8 @@ public function oneShot(
}
$corp = $data->getEveApiArguments();
$corpID = $corp['corporationID'];
/**
* @type EveApiReadWriteInterface $data
*/
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_RETRIEVE, $data);
$retrievers->retrieveEveApi($data);
if ($data->getEveApiXml() === false) {
$mess = sprintf(
Expand All @@ -144,7 +150,11 @@ public function oneShot(
->notice($mess);
return false;
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_TRANSFORM, $data);
$this->xsltTransform($data);
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_VALIDATE, $data);
if ($this->isInvalid($data)) {
$mess = sprintf(
'The data retrieved from Eve API %1$s/%2$s for %3$s is invalid',
Expand All @@ -158,6 +168,8 @@ public function oneShot(
$preservers->preserveEveApi($data);
return false;
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_PRESERVER, $data);
$preservers->preserveEveApi($data);
// No need / way to preserve XML errors to the database with normal
// preserve.
Expand Down
21 changes: 13 additions & 8 deletions lib/Database/Corp/CorporationSheet.php
Expand Up @@ -38,6 +38,7 @@
use Yapeal\Database\AttributesDatabasePreserverTrait;
use Yapeal\Database\EveApiNameTrait;
use Yapeal\Database\ValuesDatabasePreserverTrait;
use Yapeal\Event\EveApiEvent;
use Yapeal\Xml\EveApiPreserverInterface;
use Yapeal\Xml\EveApiReadWriteInterface;
use Yapeal\Xml\EveApiRetrieverInterface;
Expand All @@ -62,7 +63,8 @@ public function oneShot(
EveApiRetrieverInterface $retrievers,
EveApiPreserverInterface $preservers,
&$interval
) {
)
{
if (!$this->gotApiLock($data)) {
return false;
}
Expand All @@ -73,9 +75,8 @@ public function oneShot(
unset($corp['corporationID']);
$data->setEveApiArguments($corp);
}
/**
* @type EveApiReadWriteInterface $data
*/
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_RETRIEVE, $data);
$retrievers->retrieveEveApi($data);
if ($data->getEveApiXml() === false) {
$mess = sprintf(
Expand All @@ -88,7 +89,11 @@ public function oneShot(
->notice($mess);
return false;
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_TRANSFORM, $data);
$this->xsltTransform($data);
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_VALIDATE, $data);
if ($this->isInvalid($data)) {
$mess = sprintf(
'The data retrieved from Eve API %1$s/%2$s for %3$s is invalid',
Expand All @@ -102,6 +107,8 @@ public function oneShot(
$preservers->preserveEveApi($data);
return false;
}
$this->getYed()
->dispatchEveApiEvent(EveApiEvent::PRE_PRESERVER, $data);
$preservers->preserveEveApi($data);
// No need / way to preserve XML errors to the database with normal
// preserve.
Expand All @@ -117,10 +124,8 @@ public function oneShot(
* @throws LogicException
* @return bool
*/
protected function preserve(
$xml,
$ownerID
) {
protected function preserve($xml, $ownerID)
{
try {
$this->getPdo()
->beginTransaction();
Expand Down

0 comments on commit 3f0e8d1

Please sign in to comment.