Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code tidy #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Neman\Generatesitemapxml\Console\Command;

use Symfony\Component\Console\Command\Command;
Expand All @@ -8,38 +9,8 @@
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\App\State;

//use Magento\Framework\App\Bootstrap;
//include('app/bootstrap.php');
//$bootstrap = Bootstrap::create(BP, $_SERVER);

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('sitemap'); //gives table name with prefix

//Select Data from table
$sql = "Select * FROM " . $tableName;
$result = $connection->fetchAll($sql); // gives associated array, table fields as key in array.

if (!$result)
{
$sql = "Insert Into " . $tableName . " VALUES (1,NULL,'sitemap.xml','/',NULL,1);";
$connection->query($sql);

echo "No sitemap records found. Default (sitemap.xml) added under docroot folder.";
}

else
{
echo "Has something. We will use data from Dashboard --> Marketing --> Sitemap area or sitemap SQL table.";
}

class Generatesitemapxml extends Command
{

const NAME_ARGUMENT = "name";
const NAME_OPTION = "option";

/**
* Enable/disable configuration
*/
Expand Down Expand Up @@ -124,21 +95,14 @@ protected function execute(
InputInterface $input,
OutputInterface $output
) {


$errors = [];

// check if Marketing --> Sitemap has any fields added
//$rows = mysql_result(mysql_query('SELECT COUNT(*) FROM sitemap'), 0);


// check if scheduled generation enabled
if (!$this->_scopeConfig->isSetFlag(
self::XML_PATH_GENERATION_ENABLED,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
) {
$output->writeln('Sitemap generated at docroot. If Nginx please symlink it to pub/. No scheduled generation enabled still!!!');
$output->writeln('No generation scheduled');
}

$collection = $this->_collectionFactory->create();
Expand Down Expand Up @@ -197,10 +161,6 @@ protected function configure()
{
$this->setName("sitemap:generate");
$this->setDescription("Generate xml sitemap");
$this->setDefinition([
new InputArgument(self::NAME_ARGUMENT, InputArgument::OPTIONAL, "Name"),
new InputOption(self::NAME_OPTION, "-a", InputOption::VALUE_NONE, "Option functionality")
]);
parent::configure();
}
}