Created
February 24, 2020 00:05
-
-
Save T0MM0R/ecd030d34534080dc99ef30872df3721 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* test module for Craft CMS 3.x | |
* | |
* test | |
* | |
* @link https://thomaswilson.me | |
* @copyright Copyright (c) 2019 thomas wilson | |
*/ | |
namespace modules\rerefreshtoken\console\controllers; | |
use modules\rerefreshtoken\ReRefreshToken; | |
use Craft; | |
use craft\helpers\UrlHelper; | |
use craft\db\Query; | |
use GuzzleHttp\Client; | |
use yii\console\Controller; | |
use yii\helpers\Console; | |
/** | |
* RefreshToken Command | |
* | |
* The first line of this class docblock is displayed as the description | |
* of the Console Command in ./craft help | |
* | |
* Craft can be invoked via commandline console by using the `./craft` command | |
* from the project root. | |
* | |
* Console Commands are just controllers that are invoked to handle console | |
* actions. The segment routing is module-name/controller-name/action-name | |
* | |
* The actionIndex() method is what is executed if no sub-commands are supplied, e.g.: | |
* | |
* ./craft test-module/refresh-token | |
* | |
* Actions must be in 'kebab-case' so actionDoSomething() maps to 'do-something', | |
* and would be invoked via: | |
* | |
* ./craft test-module/refresh-token/do-something | |
* | |
* @author thomas wilson | |
* @package TestModule | |
* @since 1.0.0 | |
*/ | |
class ReRefreshTokenController extends Controller | |
{ | |
// Public Methods | |
// ========================================================================= | |
/** | |
* Handle test-module/refresh-token console commands | |
* | |
* The first line of this method docblock is displayed as the description | |
* of the Console Command in ./craft help | |
* | |
* @return mixed | |
*/ | |
public function actionIndex() | |
{ | |
$accessToken = $this->_getAccessTokenFromDb(); | |
$accessTokenObject = $this->_getAccessTokenObject($accessToken); | |
$oauthProvider = $this->_getOAuthProvider(); | |
$result = $this->_refreshAccessToken($oauthProvider, $accessToken); | |
return $result; | |
} | |
private function _getAccessTokenFromDb() | |
{ | |
$accessToken = (new Query()) | |
->select(['id','accessToken', 'refreshToken', 'expiresOn', 'expired']) | |
->from('in_raisersedge_creds')->one(); | |
return $accessToken; | |
} | |
private function _getAccessTokenObject($accessTokenFromDb) { | |
$accessToken = new \League\OAuth2\Client\Token\AccessToken([ | |
'access_token' => $accessTokenFromDb["accessToken"], | |
'refresh_token' => $accessTokenFromDb["refreshToken"], | |
'expires' => strtotime($accessTokenFromDb["expiresOn"]), | |
]); | |
return $accessToken; | |
} | |
private function _getOAuthProvider() | |
{ | |
$provider = new \League\OAuth2\Client\Provider\GenericProvider([ | |
'clientId' => 'e3a0d34d-3e1c-493c-947f-2ac9ee485b6b', | |
'clientSecret' => 'paILlFIuAO8afrLQ7d5dGaXyhkvwm/7NHQKIN7c/mWI=', | |
'redirectUri' => UrlHelper::cpUrl() . "/connect-raisers-edge", | |
'urlAuthorize' => 'https://oauth2.sky.blackbaud.com/authorization', | |
'urlAccessToken' => 'https://oauth2.sky.blackbaud.com/token', | |
'urlResourceOwnerDetails' => '' | |
]); | |
return $provider; | |
} | |
/** | |
* @return AccessTokenInterface | |
*/ | |
private function _refreshAccessToken($provider, $accessToken) { | |
$oauth = $provider->getAccessToken('refresh_token', [ | |
'refresh_token' => $accessToken["refreshToken"] | |
]); | |
Craft::$app->db->createCommand() | |
->update('in_raisersedge_creds', array( | |
'accessToken' => $oauth->getToken(), | |
'refreshToken' => $oauth->getRefreshToken(), | |
'expiresOn' => date("Y-m-d H:i:s", $oauth->getExpires()), | |
'expired' => $oauth->hasExpired() | |
), ['id' => (int)$accessToken["id"]] | |
)->execute(); | |
return $oauth; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh host@server \ | |
'cd /var/www/vhosts/sitedir/httpdocs;\ | |
git clone [email protected]:site.git;\ | |
cp site/composer.phar .;\ | |
cp -R site/src/. .;\ | |
rm -rf site;\ | |
/opt/plesk/php/7.0/bin/php composer.phar install --no-interaction --prefer-dist --optimize-autoloader;\ | |
/opt/plesk/php/7.0/bin/php ./craft migrate/all;\ | |
/opt/plesk/php/7.0/bin/php ./craft project-config/sync;\ | |
/opt/plesk/php/7.0/bin/php ./craft clear-caches/all;' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment