Skip to content

Instantly share code, notes, and snippets.

@groggu
Created September 25, 2019 19:31
Show Gist options
  • Save groggu/f4711008c79f0f04fdef70fa6a09235f to your computer and use it in GitHub Desktop.
Save groggu/f4711008c79f0f04fdef70fa6a09235f to your computer and use it in GitHub Desktop.
For use with the Porto Themes - If the Magento Proto Theme admin theme import is not working correctly, this script allows you to install themes via the command line.
<?php
/*
* Developed by Greg Croasdill
* Developed for Porto v3.1.8
* Sept 25, 2019
*
* For use with the Porto Themes (ThemeForest - http://bit.ly/2lAwRR2 or https://www.portotheme.com)
*
* Please read the Proto documentation to understand how to setup your selected Porto Theme.
*
* When to use - If the Magento Proto admin theme import is not working correctly, this script allows you to install themes via the command line.
* To use, place this script in the Magento root or shell directory
*
* Basic usage is -
*
* php installPorto --website my_website_code --demo demo12 --all --replace
*
* This will install all the demo12 CSS, settings, CMS pages and CMS Blocks into the Magento website with website code my_website_code
*
* Website and Store codes are found in the Magento admin under the System/Manage Stores page.
* Available Proto Demos can be listed using the --list options
*
* php installPorto --list
*
*/
if (file_exists(dirname($_SERVER['SCRIPT_NAME']) .'/abstract.php')) {
require_once dirname($_SERVER['SCRIPT_NAME']) . '/abstract.php';
} elseif (file_exists(dirname($_SERVER['SCRIPT_NAME']) . '/shell/abstract.php')) {
require_once dirname($_SERVER['SCRIPT_NAME']) . '/shell/abstract.php';
}
class Proto_Importer extends Mage_Shell_Abstract
{
/**
* Retrieve Usage Help Message
*
*/
public function usageHelp()
{
return <<<USAGE
Usage: php -f installPorto.php -- [options]
-h Short alias for help
--help This help
--list List of demos that are available to install (see Proto documentation for looks & styles)
--website Website name code (will install settings at the website scope)
--store Store name code (will install settings at the store scope)
--demo Name of demo to install (e.g. demo01, demo02, etc)
Demos are located in app/code/local/Smartwave/Porto/etc/import
--settings Install the CSS and demo settings
--blocks Install the CMS Blocks
--pages Install the CMS Pages
--all Install everything
--replace Replace existing CMS Blocks and Pages
USAGE;
}
public function run()
{
$list = $this->getArg('list');
if ($list) {
$this->showDemoList();
exit;
}
$websiteCode = $this->getArg('website');
$storeCode = $this->getArg('store');
$demoVersion = $this->getArg('demo');
$settings = $this->getArg('settings') == "yes" ? true : false;
$blocks = $this->getArg('blocks') == "yes" ? true : false;
$pages = $this->getArg('pages') == "yes" ? true : false;
$all = $this->getArg('all') == "yes" ? true : false;
$replace = $this->getArg('replace') == "yes" ? true : false;
$help = $this->getArg('help');
if ($help) {
$this->usageHelp();
}
if (!($websiteCode || $storeCode)) {
echo "Quitting - Website or Store Code needed\n";
die($this->usageHelp());
}
if ($websiteCode && $storeCode) {
echo "Quitting - Either Website or Store Code needed both supplied\n";
die($this->usageHelp());
}
if ($websiteCode && $websiteCode!=1) {
$id= Mage::getModel( "core/website" )->load( $websiteCode )->getId();
if ($id) {
echo "Website ID is $id \n";
} else {
echo "Error - Website $websiteCode not found\n\n";
die($this->usageHelp());
}
}
if ($storeCode && $storeCode!=1) {
$id = Mage::getModel('core/store')->loadConfig($storeCode)->getId();
if ($id) {
echo "Store ID is $id \n";
} else {
echo "Error - Store $storeCode not found\n\n";
die($this->usageHelp());
}
}
if (!$demoVersion || $demoVersion==1) {
echo "Quitting - Missing Demo Name (eg - demo01, demo02)\n";
die($this->usageHelp());
}
if (!($all || $blocks || $pages || $settings)) {
echo "Quitting - Need to know what to import\n";
die($this->usageHelp());
}
echo "Importer will import $demoVersion into ";
if ($websiteCode && $websiteCode!=1) {
echo "at the website scope in website $websiteCode ";
} else {
echo "at the store scope with store $storeCode ";
}
echo " with options -\n";
if ($all) {
echo "\tdemo css and settings,\n\tcms pages,\n\tcms blocks\n";
} else {
if ($blocks) {
echo "\tcms blocks\n";
}
if ($pages) {
echo "\tcms pages\n";
}
if ($settings) {
echo "\tdemo css and settings\n";
}
}
if ($replace) {
echo "Any existing Blocks and CMS pages will be overwitten";
} else {
echo "Any existing Blocks and CMS pages will NOT be overwitten";
}
echo "\n\nAre you sure you want to do this? It can not be undone.\nIf nervous, please take a make of your Magento database.\n\tType 'yes' to continue: ";
$handle = fopen("php://stdin", "r");
$line = fgets($handle);
if (trim($line) != 'yes') {
echo "No changes will be made\n";
exit;
}
fclose($handle);
echo "\n";
echo "Import starting\n";
if ($all) {
echo "import CSS and Settings... ";
$this->importCMS($demoVersion, $websiteCode, $storeCode);
echo "import CMS Blocks... ";
$this->importBlocks($demoVersion, $replace);
echo "import CMS Pages...";
$this->importPages($demoVersion, $replace);
} else {
if ($settings) {
echo "import CSS and Settings... ";
$this->importCMS($demoVersion, $websiteCode, $storeCode);
}
if ($blocks) {
echo "import CMS Blocks... ";
$this->importBlocks($demoVersion, $replace);
}
if ($pages) {
echo "import CMS Pages...";
$this->importPages($demoVersion, $replace);
}
}
echo "\n Done!\n\n";
}
public function importBlocks($demoVersion, $isOverwrite)
{
Mage::getSingleton('porto/import_cms')->importCms('cms/block', 'blocks', $demoVersion, $isOverwrite);
}
public function importPages($demoVersion, $isOverwrite)
{
Mage::getSingleton('porto/import_cms')->importCms('cms/page', 'pages', $demoVersion, $isOverwrite);
}
public function importCMS($demoversion, $website, $store)
{
Mage::getSingleton('porto/import_demoversion')->importDemoversion($demoversion, $store, $website);
Mage::getSingleton('porto/cssconfig_generator')->generateCss('settings', $website, $store);
Mage::getSingleton('porto/cssconfig_generator')->generateCss('design', $website, $store);
}
protected function showDemoList() {
$location = Mage::getBaseDir('app'). '/code/local/Smartwave/Porto/etc/import/';
$filenameMasks = ['Available demos - '=>'demo??.xml','"Old" format demos -'=>'demo??_old.xml'];
echo "\n\n";
foreach ($filenameMasks as $title => $fileNameMask) {
echo $title."\n";
$i=0;
foreach (glob($location.$fileNameMask) as $filename) {
$i++;
echo basename($filename,'.xml')."\t";
if ($i%5==0){
echo "\n";
}
}
echo "\n\n";
}
}
}
$shell = new Proto_Importer();
$shell->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment