[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/infrastructure/sms/storage/ -> PhabricatorSMS.php (source)

   1  <?php
   2  
   3  final class PhabricatorSMS
   4    extends PhabricatorSMSDAO {
   5  
   6    const MAXIMUM_SEND_TRIES        = 5;
   7  
   8    /**
   9     * Status constants should be 16 characters or less. See status entries
  10     * for details on what they indicate about the underlying SMS.
  11     */
  12  
  13    // in the beginning, all SMS are unsent
  14    const STATUS_UNSENT             = 'unsent';
  15    // that nebulous time when we've sent it from Phabricator but haven't
  16    // heard anything from the external API
  17    const STATUS_SENT_UNCONFIRMED   = 'sent-unconfirmed';
  18    // "success"
  19    const STATUS_SENT               = 'sent';
  20    // "fail" but we'll try again
  21    const STATUS_FAILED             = 'failed';
  22    // we're giving up on our external API partner
  23    const STATUS_FAILED_PERMANENTLY = 'permafailed';
  24  
  25    const SHORTNAME_PLACEHOLDER     = 'phabricator';
  26  
  27    protected $providerShortName;
  28    protected $providerSMSID;
  29    // numbers can be up to 20 digits long
  30    protected $toNumber;
  31    protected $fromNumber;
  32    protected $body;
  33    protected $sendStatus;
  34  
  35    public static function initializeNewSMS($body) {
  36      // NOTE: these values will be updated to correct values when the
  37      // SMS is sent for the first time. In particular, the ProviderShortName
  38      // and ProviderSMSID are totally garbage data before a send it attempted.
  39      return id(new PhabricatorSMS())
  40        ->setBody($body)
  41        ->setSendStatus(PhabricatorSMS::STATUS_UNSENT)
  42        ->setProviderShortName(PhabricatorSMS::SHORTNAME_PLACEHOLDER)
  43        ->setProviderSMSID(Filesystem::readRandomCharacters(40));
  44    }
  45  
  46    public function getConfiguration() {
  47      return array(
  48        self::CONFIG_COLUMN_SCHEMA => array(
  49          'providerShortName' => 'text16',
  50          'providerSMSID' => 'text40',
  51          'toNumber' => 'text20',
  52          'fromNumber' => 'text20?',
  53          'body' => 'text',
  54          'sendStatus' => 'text16?',
  55        ),
  56        self::CONFIG_KEY_SCHEMA => array(
  57          'key_provider' => array(
  58            'columns' => array('providerSMSID', 'providerShortName'),
  59            'unique' => true,
  60          ),
  61        ),
  62      ) + parent::getConfiguration();
  63    }
  64  
  65    public function getTableName() {
  66      // Slightly non-standard, but otherwise this class needs "MetaMTA" in its
  67      // name. :/
  68      return 'sms';
  69    }
  70  
  71    public function hasBeenSentAtLeastOnce() {
  72      return ($this->getProviderShortName() !=
  73        PhabricatorSMS::SHORTNAME_PLACEHOLDER);
  74    }
  75  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1