Exemplo n.º 1
0
 /**
  * connect to salesforce, get sforceClient
  * @return SforcePartnerClient
  */
 public static function getClient()
 {
     if (self::$_sForceClient == NULL) {
         $sforceClient = new SforcePartnerClient();
         // TODO now only partner client supported.
         $soapClient = $sforceClient->createConnection(self::$wsdlPartner);
         if (PHP_SAPI != 'cli') {
             @session_start();
             if (isset($_SESSION[self::SESSION_KEY])) {
                 $conf = $_SESSION[self::SESSION_KEY];
                 $sforceClient->setEndpoint($conf->location);
                 $sforceClient->setSessionHeader($conf->sessionId);
             } else {
                 $sforceLogin = $sforceClient->login(self::$username, self::$password . self::$securityToken);
                 $conf = new stdClass();
                 $conf->location = $sforceClient->getLocation();
                 $conf->sessionId = $sforceClient->getSessionId();
                 $_SESSION[self::SESSION_KEY] = $conf;
             }
         } else {
             $sforceLogin = $sforceClient->login(self::$username, self::$password . self::$securityToken);
         }
         self::$_sForceClient = $sforceClient;
     }
     return self::$_sForceClient;
 }
Exemplo n.º 2
0
 public function testUpdateAll()
 {
     $j = new Sobject_Jyugyoin__c();
     $j->Name = "佐藤" . time();
     $j->JyugyoinBango__c = substr(time(), 5);
     $j->Age__c = 30;
     $result = $j->insert();
     $this->assertTrue($result);
     $this->assertNotNull($j->Id);
     $j2 = new Sobject_Jyugyoin__c();
     $j2->Id = $j->Id;
     $j2->Name = "加藤";
     $j2->fieldnull('Age__c');
     $j3 = new Sobject_Jyugyoin__c();
     $j3->Name = "Kato";
     $j3->Id = '12345600';
     Srecord_Schema::updateAll(array($j2, $j3));
     $this->assertEqual($j2->getState(), Srecord_ActiveRecord::STATE_SUCCESS);
     $j4 = Sobject_Jyugyoin__c::neu()->find($j2->Id);
     $this->assertEqual($j4->Age__c, "");
     $this->assertEqual($j4->Name, "加藤");
     $this->assertEqual($j3->getState(), SRecord_ActiveRecord::STATE_FAIL);
     $errors = $j3->getErrors();
     print_r($errors);
 }
Exemplo n.º 3
0
 /**
  * generate entity
  * 
  */
 public function execute()
 {
     // connect to salesforce
     $client = Srecord_Schema::getClient();
     // get object definition
     $objectTypes = array();
     $global = $client->describeGlobal();
     foreach ($global->sobjects as $def) {
         $objectTypes[] = $def->name;
     }
     $objectDefs = array();
     $offset = 0;
     $length = 100;
     $max = count($objectTypes);
     while ($offset < $max) {
         $part = $client->describeSObjects(array_slice($objectTypes, $offset, $length));
         foreach ($part as $one) {
             // TODO arrayの+でうまくいかなかった。。
             $objectDefs[] = $one;
         }
         $offset += $length;
     }
     // generate class file
     foreach ($objectDefs as $def) {
         $this->manipMeta($def);
         $this->generate($def);
     }
 }
Exemplo n.º 4
0
 public function testUpsert()
 {
     $extid = substr(time(), 5);
     // create
     $j = new Sobject_Jyugyoin__c();
     $j->Name = "Test Member" . time();
     $j->JyugyoinBango__c = $extid;
     $j->Age__c = 30;
     Srecord_Schema::upsertAll('JyugyoinBango__c', array($j));
     $this->assertEqual($j->getState(), Srecord_ActiveRecord::STATE_SUCCESS);
     $this->assertTrue(strlen($j->Id) > 1);
 }
Exemplo n.º 5
0
 public function testDeleteAll()
 {
     $list = Sobject_Jyugyoin__c::neu()->limit(3)->select();
     Srecord_Schema::deleteAll($list);
     $this->assertEqual($list[0]->getState(), Srecord_ActiveRecord::STATE_SUCCESS);
     $this->assertEqual($list[1]->getState(), Srecord_ActiveRecord::STATE_SUCCESS);
     $this->assertEqual($list[2]->getState(), Srecord_ActiveRecord::STATE_SUCCESS);
     print " 0: " . $list[0]->Id;
     print " 1: " . $list[1]->Id;
     print " 2: " . $list[2]->Id;
     array_pop($list);
     Srecord_Schema::undeleteAll($list);
     $this->assertEqual($list[0]->getState(), Srecord_ActiveRecord::STATE_SUCCESS);
     $this->assertEqual($list[1]->getState(), Srecord_ActiveRecord::STATE_SUCCESS);
 }
Exemplo n.º 6
0
 public function testCreateAll()
 {
     $j = new Sobject_Jyugyoin__c();
     $j->Name = "佐藤" . time();
     $j2 = new Sobject_Jyugyoin__c();
     $j2->Name = "Sato" . time();
     $j2->JyugyoinBango__c = substr(time(), 5);
     // fail.
     Srecord_Schema::createAll(array($j, $j2));
     $this->assertEqual($j->getState(), Srecord_ActiveRecord::STATE_FAIL);
     $this->assertEqual($j->getErrors()->statusCode, "REQUIRED_FIELD_MISSING");
     $this->assertEqual($j->Id, "");
     $this->assertEqual($j2->getState(), Srecord_ActiveRecord::STATE_SUCCESS);
     $this->assertTrue(strlen($j2->Id) > 1);
     print $j2->Id;
 }
Exemplo n.º 7
0
//
// autoload
//
function srecord_autoload($name)
{
    $lower = strtolower($name);
    foreach (array('srecord', 'sobject', 'sobjectdef') as $target) {
        $check = $target . "_";
        if (strpos($lower, $check) === 0) {
            $filename = substr($name, strlen($check));
            include_once "{$target}/{$filename}.php";
        }
    }
}
function __autoload($clsname)
{
    srecord_autoload($clsname);
}
if (function_exists('spl_autoload_register')) {
    spl_autoload_register('srecord_autoload');
}
//ini_set('unserialize_callback_func', 'srecord_autoload');
//
// definition
//
define("PHPTOOLKIT_DIR", dirname(__FILE__) . '/phptoolkit-13_1');
Srecord_Schema::$username = '******';
Srecord_Schema::$password = '******';
Srecord_Schema::$securityToken = 'salesforcesecuritytoken';
Srecord_Schema::$wsdlPartner = dirname(__FILE__) . "/wsdl/partner.wsdl";
Exemplo n.º 8
0
 /**
  * undelete record of specified id.
  * Id must be set as a parameter or Id field.
  * if you want to undelete multiple records, use Srecord_Schema::undeleteAll() instead.
  * 
  * @param string $id
  * @return bool
  */
 public function undelete($id = NULL)
 {
     if ($id == NULL) {
         $id = $this->Id;
     }
     if ($this->_null($id) == NULL) {
         throw new SRecord_ActiveRecordException('Id is not specified.');
     }
     // connect to salesforce.
     $client = Srecord_Schema::getClient();
     $res = $client->undelete(array($id));
     if ($res->success == 1) {
         $this->_state = self::STATE_SUCCESS;
         $this->_errors = NULL;
         return TRUE;
     }
     // error.
     $this->_state = self::STATE_FAIL;
     $this->_errors = $res->errors;
     return FALSE;
 }