1 | <?php |
||
7 | class MySalesForcePartnerAPIConnectionOnly extends Object |
||
8 | { |
||
9 | private static $username = ''; |
||
10 | private static $password = ''; |
||
11 | private static $security_token = ''; |
||
12 | private static $wsdl_location = ''; |
||
13 | |||
14 | protected static $my_connection = null; |
||
15 | protected static $my_soap_client = null; |
||
16 | |||
17 | public static function singleton() |
||
43 | } |
||
44 | |||
45 | protected static function create_from_cache() |
||
46 | { |
||
47 | $sessionData = self::retrieve_cache_data(); |
||
48 | |||
49 | if (! $sessionData) { |
||
50 | return null; |
||
51 | } |
||
52 | |||
53 | $location = $sessionData['location']; |
||
54 | $sessionId = $sessionData['sessionId']; |
||
55 | |||
56 | if (! $location || ! $sessionId) { |
||
57 | return null; |
||
58 | } |
||
59 | |||
60 | $sessionHeader = new SForce\Wsdl\SessionHeader($sessionId); |
||
61 | |||
62 | if (! $sessionHeader) { |
||
63 | return null; |
||
64 | } |
||
65 | |||
66 | // Use SforceEnterpriseClient or SforcePartnerClient as appropriate |
||
67 | $wsdlLocation = Director::baseFolder() . '/' . self::config()->wsdl_location; |
||
68 | |||
69 | // Get from cache |
||
70 | self::$my_connection = new MySalesForcePartnerAPI(); |
||
71 | self::$my_connection->createConnection($wsdlLocation); |
||
72 | self::$my_connection->setEndpoint($location); |
||
73 | self::$my_connection->setSessionHeader($sessionHeader); |
||
74 | |||
75 | return self::$my_connection; |
||
76 | } |
||
77 | |||
78 | protected static function retrieve_cache_data() |
||
79 | { |
||
80 | $cache = SS_Cache::factory(self::class); |
||
81 | $location = $cache->load('location'); |
||
82 | $sessionId = $cache->load('sessionId'); |
||
83 | |||
84 | return [ |
||
85 | 'location' => $location, |
||
86 | 'sessionId' => $sessionId, |
||
87 | ]; |
||
88 | } |
||
89 | |||
90 | |||
91 | public static function debug($showSessionID = false) |
||
107 | } |
||
108 | } |
||
109 |