mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 12:30:56 +01:00
Make it possible for applications to generate concrete subscriptions
Summary: Ref T6881. This still doesn't "work" in any reasonable sense of the word, but gets us a bit further. I'll build out the Phortune UI a little bit next, then look at implementing the Worker to do actual billing. Test Plan: - Allocated an instance and saw a Subscription generate properly. - Saw subscription show up in the Phortune UI, albeit in a very limited way. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6881 Differential Revision: https://secure.phabricator.com/D11575
This commit is contained in:
parent
77eae81e1a
commit
4adc2d8a72
4 changed files with 97 additions and 6 deletions
|
@ -275,8 +275,11 @@ final class PhortuneAccountViewController extends PhortuneController {
|
|||
$subscriptions_uri = $this->getApplicationURI(
|
||||
$account->getID().'/subscription/');
|
||||
|
||||
$handles = $this->loadViewerHandles(mpull($subscriptions, 'getPHID'));
|
||||
|
||||
$table = id(new PhortuneSubscriptionTableView())
|
||||
->setUser($viewer)
|
||||
->setHandles($handles)
|
||||
->setSubscriptions($subscriptions);
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
|
|
|
@ -85,13 +85,16 @@ final class PhortuneSubscriptionQuery
|
|||
$subscription_map = mgroup($subscriptions, 'getSubscriptionClass');
|
||||
foreach ($subscription_map as $class => $class_subscriptions) {
|
||||
$sub = newv($class, array());
|
||||
$implementations += $sub->loadImplementationsForSubscriptions(
|
||||
$impl_objects = $sub->loadImplementationsForRefs(
|
||||
$this->getViewer(),
|
||||
$class_subscriptions);
|
||||
mpull($class_subscriptions, 'getSubscriptionRef'));
|
||||
|
||||
$implementations += mpull($impl_objects, null, 'getRef');
|
||||
}
|
||||
|
||||
foreach ($subscriptions as $key => $subscription) {
|
||||
$implementation = idx($implementations, $key);
|
||||
$ref = $subscription->getSubscriptionRef();
|
||||
$implementation = idx($implementations, $ref);
|
||||
if (!$implementation) {
|
||||
unset($subscriptions[$key]);
|
||||
continue;
|
||||
|
|
|
@ -138,6 +138,7 @@ final class PhortuneSubscriptionSearchEngine
|
|||
|
||||
$table = id(new PhortuneSubscriptionTableView())
|
||||
->setUser($viewer)
|
||||
->setHandles($handles)
|
||||
->setSubscriptions($subscriptions);
|
||||
|
||||
$merchant = $this->getMerchant();
|
||||
|
|
|
@ -58,19 +58,66 @@ final class PhortuneSubscription extends PhortuneDAO
|
|||
PhortuneSubscriptionPHIDType::TYPECONST);
|
||||
}
|
||||
|
||||
public static function initializeNewSubscription() {
|
||||
return id(new PhortuneSubscription());
|
||||
public static function initializeNewSubscription(
|
||||
PhortuneAccount $account,
|
||||
PhortuneMerchant $merchant,
|
||||
PhabricatorUser $author,
|
||||
PhortuneSubscriptionImplementation $implementation,
|
||||
PhabricatorTriggerClock $clock) {
|
||||
|
||||
$trigger = id(new PhabricatorWorkerTrigger())
|
||||
->setClock($clock);
|
||||
|
||||
return id(new PhortuneSubscription())
|
||||
->setStatus(self::STATUS_ACTIVE)
|
||||
->setAccountPHID($account->getPHID())
|
||||
->attachAccount($account)
|
||||
->setMerchantPHID($merchant->getPHID())
|
||||
->attachMerchant($merchant)
|
||||
->setAuthorPHID($author->getPHID())
|
||||
->setSubscriptionClass(get_class($implementation))
|
||||
->setSubscriptionRef($implementation->getRef())
|
||||
->attachImplementation($implementation)
|
||||
->attachTrigger($trigger);
|
||||
}
|
||||
|
||||
public function attachImplementation(
|
||||
PhortuneSubscriptionImplementation $impl) {
|
||||
$this->implementation = $impl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getImplementation() {
|
||||
return $this->assertAttached($this->implementation);
|
||||
}
|
||||
|
||||
public function attachAccount(PhortuneAccount $account) {
|
||||
$this->account = $account;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAccount() {
|
||||
return $this->assertAttached($this->account);
|
||||
}
|
||||
|
||||
public function attachMerchant(PhortuneMerchant $merchant) {
|
||||
$this->merchant = $merchant;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMerchant() {
|
||||
return $this->assertAttached($this->merchant);
|
||||
}
|
||||
|
||||
public function attachTrigger(PhabricatorWorkerTrigger $trigger) {
|
||||
$this->trigger = $trigger;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTrigger() {
|
||||
return $this->assertAttached($this->trigger);
|
||||
}
|
||||
|
||||
public function save() {
|
||||
$this->subscriptionClassKey = PhabricatorHash::digestForIndex(
|
||||
$this->subscriptionClass);
|
||||
|
@ -78,7 +125,44 @@ final class PhortuneSubscription extends PhortuneDAO
|
|||
$this->subscriptionRefKey = PhabricatorHash::digestForIndex(
|
||||
$this->subscriptionRef);
|
||||
|
||||
return parent::save();
|
||||
$trigger = $this->getTrigger();
|
||||
$is_new = (!$this->getID());
|
||||
|
||||
$this->openTransaction();
|
||||
|
||||
// If we're saving this subscription for the first time, we're also
|
||||
// going to set up the trigger for it.
|
||||
if ($is_new) {
|
||||
$trigger_phid = PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorWorkerTriggerPHIDType::TYPECONST);
|
||||
$this->setTriggerPHID($trigger_phid);
|
||||
}
|
||||
|
||||
$result = parent::save();
|
||||
|
||||
if ($is_new) {
|
||||
$trigger_action = new PhabricatorScheduleTaskTriggerAction(
|
||||
array(
|
||||
'class' => 'PhortuneSubscriptionWorker',
|
||||
'data' => array(
|
||||
'subscriptionPHID' => $this->getPHID(),
|
||||
),
|
||||
'options' => array(
|
||||
'objectPHID' => $this->getPHID(),
|
||||
'priority' => PhabricatorWorker::PRIORITY_BULK,
|
||||
),
|
||||
));
|
||||
|
||||
$trigger->setAction($trigger_action);
|
||||
$trigger->save();
|
||||
}
|
||||
$this->saveTransaction();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getSubscriptionName() {
|
||||
return $this->getImplementation()->getName($this);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue