-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New cli console && rename directory (#808)
- Loading branch information
Showing
46 changed files
with
1,074 additions
and
1,049 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
.DS_Store | ||
scripts/vendor/vendor | ||
scripts/vendor/data/* | ||
bin/vendor/vendor | ||
bin/scripts/data/* | ||
issues/ | ||
csc/ | ||
base.php | ||
.idea | ||
/bin/vendor/ | ||
composer.lock | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
APP_ENVIRONMENT=production |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
|
||
namespace bin\Commands; | ||
|
||
use bin\Support\Config; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ExportCscNpm extends Command | ||
{ | ||
protected static $defaultName = 'export:export-csc-npm'; | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$db = Config::getConfig()->getDB(); | ||
$rootDir = PATH_BASE . '../..'; | ||
|
||
$i = 0; | ||
$j = 0; | ||
$k = 0; | ||
|
||
$countriesArray = array(); | ||
$statesArray = array(); | ||
$citiesArray = array(); | ||
|
||
$sql = "SELECT * FROM countries"; | ||
$result = $db->query($sql); | ||
if ($result->num_rows > 0) { | ||
while ($row = $result->fetch_assoc()) { | ||
// Pushing it into Fresh Array | ||
$countriesArray[$i]['isoCode'] = $row['iso2']; | ||
$countriesArray[$i]['name'] = $row['name']; | ||
$countriesArray[$i]['phonecode'] = $row['phonecode']; | ||
$countriesArray[$i]['flag'] = $row['emoji']; | ||
$countriesArray[$i]['currency'] = $row['currency']; | ||
$countriesArray[$i]['latitude'] = $row['latitude']; | ||
$countriesArray[$i]['longitude'] = $row['longitude']; | ||
$countriesArray[$i]['timezones'] = json_decode($row['timezones'], true); | ||
|
||
$i++; | ||
} | ||
} | ||
|
||
|
||
$sql = "SELECT * FROM states"; | ||
$result = $db->query($sql); | ||
if ($result->num_rows > 0) { | ||
while ($row = $result->fetch_assoc()) { | ||
// Pushing it into Fresh Array | ||
$statesArray[$j]['name'] = $row['name']; | ||
$statesArray[$j]['isoCode'] = $row['iso2']; | ||
$statesArray[$j]['countryCode'] = $row['country_code']; | ||
$statesArray[$j]['latitude'] = $row['latitude']; | ||
$statesArray[$j]['longitude'] = $row['longitude']; | ||
|
||
$j++; | ||
} | ||
} | ||
|
||
|
||
$sql = "SELECT * FROM cities"; | ||
$result = $db->query($sql); | ||
if ($result->num_rows > 0) { | ||
while ($row = $result->fetch_assoc()) { | ||
// Pushing it into Fresh Array | ||
$citiesArray[$k]['name'] = $row['name']; | ||
$citiesArray[$k]['countryCode'] = $row['country_code']; | ||
$citiesArray[$k]['stateCode'] = $row['state_code']; | ||
$citiesArray[$k]['latitude'] = $row['latitude']; | ||
$citiesArray[$k]['longitude'] = $row['longitude']; | ||
|
||
$k++; | ||
} | ||
} | ||
|
||
$output->writeln('Total Countries Count : ' . count($countriesArray)); | ||
$output->writeln('Total States Count : ' . count($statesArray)); | ||
$output->writeln('Total Cities Count : ' . count($citiesArray)); | ||
|
||
|
||
$exportTo = $rootDir . '/csc/country.json'; | ||
if(!is_dir($rootDir . '/csc')){ | ||
mkdir($rootDir . '/csc', 777, true); | ||
} | ||
$fp = fopen($exportTo, 'w'); // Putting Array to JSON | ||
fwrite($fp, json_encode($countriesArray, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL); | ||
$output->writeln('JSON Exported to ' . $exportTo); | ||
fclose($fp); | ||
|
||
|
||
$exportTo = $rootDir . '/csc/state.json'; | ||
$fp = fopen($exportTo, 'w'); // Putting Array to JSON | ||
fwrite($fp, json_encode($statesArray, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL); | ||
$output->writeln('JSON Exported to ' . $exportTo); | ||
fclose($fp); | ||
|
||
|
||
$exportTo = $rootDir . '/csc/city.json'; | ||
$fp = fopen($exportTo, 'w'); // Putting Array to JSON | ||
fwrite($fp, json_encode($citiesArray, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL); | ||
$output->writeln('JSON Exported to ' . $exportTo); | ||
fclose($fp); | ||
|
||
$db->close(); | ||
return 1; | ||
|
||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
|
||
namespace bin\Commands; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ExportCsv extends Command | ||
{ | ||
protected static $defaultName = 'export:export-csv'; | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
|
||
$rootDir = PATH_BASE . '../..'; | ||
|
||
$files = array( | ||
'countries' => array( | ||
'from' => '/countries.json', | ||
'to' => '/csv/countries.csv', | ||
), | ||
'states' => array( | ||
'from' => '/states.json', | ||
'to' => '/csv/states.csv', | ||
), | ||
'cities' => array( | ||
'from' => '/cities.json', | ||
'to' => '/csv/cities.csv', | ||
), | ||
'regions' => array( | ||
'from' => '/regions.json', | ||
'to' => '/csv/regions.csv', | ||
), | ||
'subregions' => array( | ||
'from' => '/subregions.json', | ||
'to' => '/csv/subregions.csv', | ||
), | ||
); | ||
|
||
foreach ($files as $root => $v) { | ||
// Gets JSON file | ||
$json = file_get_contents($rootDir . $v['from']); | ||
|
||
$csc = json_decode($json, true); | ||
|
||
$fp = fopen($rootDir . $v['to'], 'w'); // Putting Array to XML | ||
|
||
// Set headings | ||
$headings = $csc[0]; | ||
|
||
// No translations please. | ||
unset($headings['translations']); | ||
fputcsv($fp, array_keys($headings)); | ||
|
||
// Loop through the associative array. | ||
foreach ($csc as $row) { | ||
// Update timezones to make readable | ||
if (!empty($row['timezones'])) { | ||
$row['timezones'] = json_encode($row['timezones']); | ||
$row['timezones'] = preg_replace('/"/', "'", $row['timezones']); | ||
$row['timezones'] = preg_replace("/'([a-zA-Z]+[a-zA-Z0-9_]*)':/", '$1:', $row['timezones']); | ||
} | ||
|
||
// No translations please. | ||
unset($row['translations']); | ||
|
||
// Write the row to the CSV file. | ||
fputcsv($fp, $row); | ||
}; | ||
|
||
fclose($fp); | ||
|
||
$output->writeln( 'CSV Exported to ' . $rootDir . $v['to'] ); | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
} |
Oops, something went wrong.