-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli
96 lines (71 loc) · 2.11 KB
/
cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
# Dev Mode: Show Errors
ini_set('display_errors', true);
ini_set('display_startup_erros', true);
error_reporting(E_ALL);
# Constants
define('UPXFORMS_PATH', __DIR__ . '/');
define('UPXFORMS_INC', UPXFORMS_PATH . 'inc/');
define('UPXFORMS_LOGS', UPXFORMS_PATH . 'logs/');
define('UPXFORMS_LOG_FILE', UPXFORMS_LOGS . 'logs.txt');
define('UPXFORMS_LOGS_ON', true);
# Includes
require __DIR__ . '/vendor/autoload.php';
include __DIR__ . '/inc/logs.php';
include __DIR__ . '/inc/UpxForms.php';
# WP Core
include dirname(__DIR__, 3) . '/wp-config.php';
use Microframeworks\UpxForms;
if (php_sapi_name() != 'cli') {
exit('This application must be run on the command line.');
}
upx_log('UpxForms: cli linha de comando em execução...');
$arg = $argv[1] ?? null;
if (empty($arg)) {
echo 'show: var dump em options' . PHP_EOL;
echo 'list: mostrar conteudo na planilha' . PHP_EOL;
echo 'insert: insere dados do mock na planilha' . PHP_EOL;
exit;
}
$options = get_option('upxforms_api_settings');
if ($arg=='show') {
update_option('upxforms_api_settings', ['planilha' => 'planilha']); // limpar dados
var_dump($options);
exit;
}
if (empty($options['planilha'])) {
upx_log_exit('Erro: ID de planilha ausente.');
}
if (empty($options['credenciais'])) {
upx_log_exit('Erro: credenciais ausentes.');
}
if (empty($options['token'])) {
upx_log_exit('Erro: token ausente.');
}
$callback = function($options){
update_option('upxforms_api_settings', $options);
};
if ($arg=='insert') {
upx_log('Inserindo mock de teste...');
$newRow = [
'Teste',
'Outro teste',
'https://image.tmdb.org/t/p/w500/bQY.jpg',
"Alguma longa frase sobre alguma coisa.",
'123123123',
'São Paulo, SP',
date('Y-m-d H:i:s')
];
$rows = [$newRow];
$valueRange = UpxForms::valueRange();
$valueRange->setValues($rows);
$googleOptions = ['valueInputOption' => 'USER_ENTERED'];
UpxForms::insertRows($options['planilha'], 'Sheet1', $valueRange, $googleOptions, $options, $callback);
exit;
}
if ($arg=='list') {
upx_log('Listando...');
$u = UpxForms::getAll($options['planilha'], 'Sheet1', $options, $callback);
var_dump($u);
exit;
}