1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CakePHPify : CakePHP Plugin for Shopify API Authentication |
4
|
|
|
* Copyright (c) Multidimension.al (http://multidimension.al) |
5
|
|
|
* Github : https://github.com/multidimension-al/cakephpify |
6
|
|
|
* |
7
|
|
|
* Licensed under The MIT License |
8
|
|
|
* For full copyright and license information, please see the LICENSE file |
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
10
|
|
|
* |
11
|
|
|
* @copyright (c) Multidimension.al (http://multidimension.al) |
12
|
|
|
* @link https://github.com/multidimension-al/cakephpify CakePHPify Github |
13
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
namespace Multidimensional\Cakephpify\Shell; |
18
|
|
|
|
19
|
|
|
use Cake\Core\Configure; |
20
|
|
|
use Cake\Console\Shell; |
21
|
|
|
use Cake\Console\Helper; |
22
|
|
|
use Migrations\Migrations; |
23
|
|
|
|
24
|
|
|
class ShopifyInstallShell extends Shell |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
public function main() |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
$this->clear(); |
31
|
|
|
|
32
|
|
|
$this->_io->styles('error', ['text' => 'red']); |
33
|
|
|
$this->helper('Multidimensional/Cakephpify.Header')->output(); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$first_run = ((Configure::check('Multidimensional/Cakephpify')) ? false : true); |
|
|
|
|
36
|
|
|
|
37
|
|
|
//Activate Plugin |
38
|
|
|
if ((($first_run) ? (strtolower($this->in('Install Shopify Plugin?', ['y','n'])) == 'y') : (strtolower($this->in('Update Configuration?', ['y','n'])) == 'y'))) { |
|
|
|
|
39
|
|
|
|
40
|
|
|
|
41
|
|
|
$this->out(); |
42
|
|
|
$this->out('Please enter your API credentials from your Shopify App page.', 2); |
43
|
|
|
$apiKey = $this->in('API Key:'); |
|
|
|
|
44
|
|
|
$this->out(); |
45
|
|
|
|
46
|
|
|
Configure::write('Multidimensional/Cakephpify.' . $api_key . '.shared_secret', $this->in('Shared Secret:')); |
|
|
|
|
47
|
|
|
|
48
|
|
|
$this->out(); |
49
|
|
|
|
50
|
|
|
$scopeArray = ['read_content', 'write_content', 'read_themes', 'write_themes', 'read_products', 'write_products', 'read_customers', 'write_customers', 'read_orders', 'write_orders', 'read_script_tags', 'write_script_tags', 'read_fulfillments', 'write_fulfillments', 'read_shipping', 'write_shipping', 'read_analytics', 'read_users', 'write_users']; |
51
|
|
|
|
52
|
|
|
$this->out('Enter your application\'s scope here.', 2); |
53
|
|
|
$this->out('Valid scope options:', 2); |
54
|
|
|
$this->helper('Multidimensional/Cakephpify.Table')->output($scopeArray); |
55
|
|
|
$this->out(''); |
56
|
|
|
$this->out('Separate your desired scope options with a comma.'); |
57
|
|
|
|
58
|
|
|
do { |
59
|
|
|
$this->out(''); |
60
|
|
|
$scope = $this->in('Scope:'); |
61
|
|
|
|
62
|
|
|
$scope = explode(",", $scope); |
63
|
|
|
|
64
|
|
|
if (!is_array($scope)) { |
65
|
|
|
$scope = [$scope]; |
66
|
|
|
} |
67
|
|
|
$scope = array_map('trim', $scope); |
68
|
|
|
$scope = array_map('strtolower', $scope); |
69
|
|
|
array_walk($scope, function (&$value) { |
70
|
|
|
$value = str_replace(" ", "_", $value); |
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
if ((count($scope)) && (strlen(trim(implode("", $scope))) > 0) && (count(array_diff($scope, $scopeArray)) > 0)) { |
74
|
|
|
$this->out(''); |
75
|
|
|
$this->_io->out('<error>Invalid Scope. Try again, or leave blank to continue.</error>'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} while((count($scope)) && (strlen(trim(implode("", $scope))) > 0) && (count(array_diff($scope, $scope_array)) > 0)); |
|
|
|
|
79
|
|
|
|
80
|
|
|
Configure::write('Multidimensional/Cakephpify.' . $api_key . '.scope',implode(',', $scope)); |
|
|
|
|
81
|
|
|
|
82
|
|
|
$this->out(''); |
83
|
|
|
$isPrivateApp = strtolower($this->in('Is this a private app?', ['y', 'n'])); |
84
|
|
|
|
85
|
|
|
if ($isPrivateApp == 'y') { |
86
|
|
|
$isPrivateApp = 'true'; |
|
|
|
|
87
|
|
|
} else { |
88
|
|
|
$isPrivateApp = 'false'; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
Configure::write('Multidimensional/Cakephpify.' . $api_key . '.is_private_app',$is_private_app); |
|
|
|
|
93
|
|
|
|
94
|
|
|
if ($is_private_app == 'true') { |
|
|
|
|
95
|
|
|
Configure::write('Multidimensional/Cakephpify.' . $api_key . '.private_app_password',$this->in('Private App Password:')); |
|
|
|
|
96
|
|
|
} else { |
97
|
|
|
Configure::write('Multidimensional/Cakephpify.' . $api_key . '.private_app_password', NULL); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
Configure::dump('shopify', 'default', ['Multidimensional/Cakephpify']); |
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$this->out(''); |
105
|
|
|
|
106
|
|
|
if (($firstRun) || (strtolower($this->in('Update Database?', ['y', 'n'])) == 'y')) { |
|
|
|
|
107
|
|
|
$this->out(''); |
108
|
|
|
|
109
|
|
|
$migrations = new Migrations(['plugin' => 'Multidimensional/Cakephpify']); |
110
|
|
|
|
111
|
|
|
$status = $migrations->status(); |
112
|
|
|
|
113
|
|
|
if ((is_array($status)) && (count($status))) { |
114
|
|
|
$this->out('Updating Databases', 2); |
115
|
|
|
|
116
|
|
|
if ($migrations->migrate()) { |
117
|
|
|
$this->out('Success!', 2); |
118
|
|
|
} else { |
119
|
|
|
$this->_io->out('<error>Update Failed!</error>', 2); |
120
|
|
|
} |
121
|
|
|
} else { |
122
|
|
|
$this->out('Shopify Database Files Not Found', 2); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
This check looks for function calls that miss required arguments.