Last active
January 4, 2019 14:36
-
-
Save azhurb/b6c2b20a8f64f8bff129561e2dd11d5e to your computer and use it in GitHub Desktop.
Update launcher config in DB using modified package.json
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 | |
if (php_sapi_name() != "cli") { | |
exit; | |
} | |
include "../common.php"; | |
use Stalker\Lib\Core\Mysql; | |
use Stalker\Lib\Core\Config; | |
array_shift($argv); | |
if (empty($argv)){ | |
die('Please specify app name'.PHP_EOL); | |
} | |
$alias = $argv[0]; | |
$app = Mysql::getInstance()->from('launcher_apps')->where(array('alias' => $alias))->get()->first(); | |
if (empty($app)){ | |
die('App '.$alias.' not found in db'.PHP_EOL); | |
} | |
$info = file_get_contents(realpath(PROJECT_PATH.'/../../' | |
.Config::getSafe('launcher_apps_path', 'stalker_launcher_apps/') | |
.($app['type'] == 'plugin' ? 'plugins/' : '') | |
.$app['alias'] | |
.'/'.$app['current_version'].'/package.json')); | |
if (!$info){ | |
die('App '.$alias.' not found in file system'.PHP_EOL); | |
} | |
$info = json_decode($info, true); | |
if (!$info){ | |
die('App '.$alias.' has not valid package.json'.PHP_EOL); | |
} | |
$update_data = array(); | |
if (!empty($info['config'])){ | |
$update_data['config'] = json_encode($info['config']); | |
} | |
$update_data['type'] = isset($info['config']['type']) ? $info['config']['type'] : null; | |
if (!empty($info['config']['name'])){ | |
$update_data['name'] = $update_data['type'] == 'app' && isset($info['config']['name']) ? $info['config']['name'] : (!empty($info['name']) ? $info['name'] : $app['url']); | |
} | |
if (!empty($info['config']['description'])) { | |
$update_data['description'] = isset($info['config']['description']) ? $info['config']['description'] : (isset($info['description']) ? $info['description'] : ''); | |
} | |
echo 'Updating add info...'; | |
$result = Mysql::getInstance()->update('launcher_apps', | |
$update_data, | |
array('alias' => $alias) | |
)->result(); | |
echo $result ? 'OK' : 'Fail'; | |
echo PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment