|
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\Console\Helper; |
|
20
|
|
|
use Cake\Console\Shell; |
|
21
|
|
|
use Cake\Core\Configure; |
|
22
|
|
|
use Migrations\Migrations; |
|
23
|
|
|
|
|
24
|
|
|
class ShopifyInstallShell extends Shell |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
public function main() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->clear(); |
|
33
|
|
|
|
|
34
|
|
|
$this->_io->styles('error', ['text' => 'red']); |
|
35
|
|
|
$this->helper('Multidimensional/Cakephpify.Header')->output(); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$firstRun = ((Configure::check('Multidimensional/Cakephpify')) ? false : true); |
|
38
|
|
|
|
|
39
|
|
|
//Activate Plugin |
|
40
|
|
|
if ((($firstRun) ? (strtolower($this->in('Install Shopify Plugin?', ['y', 'n'])) == 'y') : (strtolower($this->in('Update Configuration?', ['y', 'n'])) == 'y')) |
|
41
|
|
|
) { |
|
42
|
|
|
$this->out(); |
|
43
|
|
|
$this->out('Please enter your API credentials from your Shopify App page.', 2); |
|
44
|
|
|
$apiKey = $this->in('API Key:'); |
|
45
|
|
|
$this->out(); |
|
46
|
|
|
|
|
47
|
|
|
Configure::write('Multidimensional/Cakephpify.' . $apiKey . '.sharedSecret', $this->in('Shared Secret:')); |
|
48
|
|
|
|
|
49
|
|
|
$this->out(); |
|
50
|
|
|
|
|
51
|
|
|
$scopeArray = [ |
|
52
|
|
|
'read_content', |
|
53
|
|
|
'write_content', |
|
54
|
|
|
'read_themes', |
|
55
|
|
|
'write_themes', |
|
56
|
|
|
'read_products', |
|
57
|
|
|
'write_products', |
|
58
|
|
|
'read_customers', |
|
59
|
|
|
'write_customers', |
|
60
|
|
|
'read_orders', |
|
61
|
|
|
'write_orders', |
|
62
|
|
|
'read_script_tags', |
|
63
|
|
|
'write_script_tags', |
|
64
|
|
|
'read_fulfillments', |
|
65
|
|
|
'write_fulfillments', |
|
66
|
|
|
'read_shipping', |
|
67
|
|
|
'write_shipping', |
|
68
|
|
|
'read_analytics', |
|
69
|
|
|
'read_users', |
|
70
|
|
|
'write_users']; |
|
71
|
|
|
|
|
72
|
|
|
$this->out('Enter your application\'s scope here.', 2); |
|
73
|
|
|
$this->out('Valid scope options:', 2); |
|
74
|
|
|
$this->helper('Multidimensional/Cakephpify.Table')->output($scopeArray); |
|
75
|
|
|
$this->out(''); |
|
76
|
|
|
$this->out('Separate your desired scope options with a comma.'); |
|
77
|
|
|
|
|
78
|
|
|
do { |
|
79
|
|
|
$this->out(''); |
|
80
|
|
|
$scope = $this->in('Scope:'); |
|
81
|
|
|
|
|
82
|
|
|
$scope = explode(",", $scope); |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
if (!is_array($scope)) { |
|
85
|
|
|
$scope = [$scope]; |
|
86
|
|
|
} |
|
87
|
|
|
$scope = array_map('trim', $scope); |
|
88
|
|
|
$scope = array_map('strtolower', $scope); |
|
89
|
|
|
array_walk( |
|
90
|
|
|
$scope, |
|
91
|
|
|
function (&$value) { |
|
92
|
|
|
$value = str_replace(" ", "_", $value); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
); |
|
95
|
|
|
|
|
96
|
|
|
if ((count($scope)) && (strlen(trim(implode("", $scope))) > 0) && (count(array_diff($scope, $scopeArray)) > 0)) { |
|
|
|
|
|
|
97
|
|
|
$this->out(''); |
|
98
|
|
|
$this->_io->out('<error>Invalid Scope. Try again, or leave blank to continue.</error>'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$count = count($scope); |
|
102
|
|
|
$scopeLength = strlen(trim(implode("", $scope))); |
|
|
|
|
|
|
103
|
|
|
$scopeDiffCount = count(array_diff($scope, $scopeArray)); |
|
104
|
|
|
} while ($count && $scopeLength > 0 && $scopeDiffCount > 0); |
|
105
|
|
|
|
|
106
|
|
|
Configure::write('Multidimensional/Cakephpify.' . $apiKey . '.scope', implode(',', $scope)); |
|
107
|
|
|
|
|
108
|
|
|
$this->out(''); |
|
109
|
|
|
$isPrivateApp = strtolower($this->in('Is this a private app?', ['y', 'n'])); |
|
110
|
|
|
|
|
111
|
|
|
if ($isPrivateApp == 'y') { |
|
112
|
|
|
$isPrivateApp = 'true'; |
|
113
|
|
|
} else { |
|
114
|
|
|
$isPrivateApp = 'false'; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
Configure::write('Multidimensional/Cakephpify.' . $apiKey . '.privateApp', $isPrivateApp); |
|
119
|
|
|
|
|
120
|
|
|
if ($isPrivateApp == 'true') { |
|
121
|
|
|
Configure::write('Multidimensional/Cakephpify.' . $apiKey . '.privateAppPassword', $this->in('Private App Password:')); |
|
122
|
|
|
} else { |
|
123
|
|
|
Configure::write('Multidimensional/Cakephpify.' . $apiKey . '.privateAppPassword', null); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
Configure::dump('shopify', 'default', ['Multidimensional/Cakephpify']); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$this->out(''); |
|
130
|
|
|
|
|
131
|
|
|
if (($firstRun) || (strtolower($this->in('Update Database?', ['y', 'n'])) == 'y')) { |
|
132
|
|
|
$this->out(''); |
|
133
|
|
|
|
|
134
|
|
|
$migrations = new Migrations(['plugin' => 'Multidimensional/Cakephpify']); |
|
135
|
|
|
|
|
136
|
|
|
$status = $migrations->status(); |
|
137
|
|
|
|
|
138
|
|
|
if ((is_array($status)) && (count($status))) { |
|
139
|
|
|
$this->out('Updating Databases', 2); |
|
140
|
|
|
|
|
141
|
|
|
if ($migrations->migrate()) { |
|
142
|
|
|
$this->out('Success!', 2); |
|
143
|
|
|
} else { |
|
144
|
|
|
$this->_io->out('<error>Update Failed!</error>', 2); |
|
145
|
|
|
} |
|
146
|
|
|
} else { |
|
147
|
|
|
$this->out('Shopify Database Files Not Found', 2); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
This check looks for function calls that miss required arguments.