Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Sitemap Class Reference
Inheritance diagram for Sitemap:
AbstractModel IdentityInterface DataObject

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Escaper $escaper, \Magento\Sitemap\Helper\Data $sitemapData, \Magento\Framework\Filesystem $filesystem, \Magento\Sitemap\Model\ResourceModel\Catalog\CategoryFactory $categoryFactory, \Magento\Sitemap\Model\ResourceModel\Catalog\ProductFactory $productFactory, \Magento\Sitemap\Model\ResourceModel\Cms\PageFactory $cmsFactory, \Magento\Framework\Stdlib\DateTime\DateTime $modelDate, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\RequestInterface $request, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], \Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot=null, ItemProviderInterface $itemProvider=null, SitemapConfigReaderInterface $configReader=null, \Magento\Sitemap\Model\SitemapItemInterfaceFactory $sitemapItemFactory=null)
 
 addSitemapItem (DataObject $sitemapItem)
 
 beforeSave ()
 
 getSitemapUrl ($sitemapPath, $sitemapFileName)
 
 getIdentities ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const OPEN_TAG_KEY = 'start'
 
const CLOSE_TAG_KEY = 'end'
 
const INDEX_FILE_PREFIX = 'sitemap'
 
const TYPE_INDEX = 'sitemap'
 
const TYPE_URL = 'url'
 
const LAST_MOD_MIN_VAL = '0000-01-01 00:00:00'
 

Protected Member Functions

 _construct ()
 
 _getStream ()
 
 _initSitemapItems ()
 
 _createSitemapIndex ()
 
 _getCurrentDateTime ()
 
 _isSplitRequired ($row)
 
 _getSitemapRow ($url, $lastmod=null, $changefreq=null, $priority=null, $images=null)
 
 _getSitemapIndexRow ($sitemapFilename, $lastmod=null)
 
 _createSitemap ($fileName=null, $type=self::TYPE_URL)
 
 _writeSitemapRow ($row)
 
 _finalizeSitemap ($type=self::TYPE_URL)
 
 _getCurrentSitemapFilename ($index)
 
 _getBaseDir ()
 
 _getUrl ($url, $type=UrlInterface::URL_TYPE_LINK)
 
 _getMediaUrl ($url)
 
 _getFormattedLastmodDate ($date)
 
 _getDocumentRoot ()
 
 _getStoreBaseDomain ()
 
 _isEnabledSubmissionRobots ()
 
 _addSitemapToRobotsTxt ($sitemapFileName)
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_filePath
 
 $_sitemapItems = []
 
 $_sitemapIncrement = 0
 
 $_tags = []
 
 $_lineCount = 0
 
 $_fileSize = 0
 
 $_directory
 
 $_stream
 
 $_sitemapData
 
 $_escaper
 
 $_categoryFactory
 
 $_productFactory
 
 $_cmsFactory
 
 $_dateModel
 
 $_storeManager
 
 $_request
 
 $dateTime
 
 $_cacheTag = true
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

@method string getSitemapType() @method \Magento\Sitemap\Model\Sitemap setSitemapType(string $value) @method string getSitemapFilename() @method \Magento\Sitemap\Model\Sitemap setSitemapFilename(string $value) @method string getSitemapPath() @method \Magento\Sitemap\Model\Sitemap setSitemapPath(string $value) @method string getSitemapTime() @method \Magento\Sitemap\Model\Sitemap setSitemapTime(string $value) @method int getStoreId() @method \Magento\Sitemap\Model\Sitemap setStoreId(int $value) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.CouplingBetweenObjects) @api

Since
100.0.2

Definition at line 33 of file Sitemap.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Escaper  $escaper,
\Magento\Sitemap\Helper\Data  $sitemapData,
\Magento\Framework\Filesystem  $filesystem,
\Magento\Sitemap\Model\ResourceModel\Catalog\CategoryFactory  $categoryFactory,
\Magento\Sitemap\Model\ResourceModel\Catalog\ProductFactory  $productFactory,
\Magento\Sitemap\Model\ResourceModel\Cms\PageFactory  $cmsFactory,
\Magento\Framework\Stdlib\DateTime\DateTime  $modelDate,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\App\RequestInterface  $request,
\Magento\Framework\Stdlib\DateTime  $dateTime,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [],
\Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot  $documentRoot = null,
ItemProviderInterface  $itemProvider = null,
SitemapConfigReaderInterface  $configReader = null,
\Magento\Sitemap\Model\SitemapItemInterfaceFactory  $sitemapItemFactory = null 
)

Initialize dependencies.

Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Escaper$escaper
\Magento\Sitemap\Helper\Data$sitemapData
\Magento\Framework\Filesystem$filesystem
ResourceModel\Catalog\CategoryFactory$categoryFactory
ResourceModel\Catalog\ProductFactory$productFactory
ResourceModel\Cms\PageFactory$cmsFactory
\Magento\Framework\Stdlib\DateTime\DateTime$modelDate
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\App\RequestInterface$request
\Magento\Framework\Stdlib\DateTime$dateTime
\Magento\Framework\Model\ResourceModel\AbstractResource | null$resource
\Magento\Framework\Data\Collection\AbstractDb | null$resourceCollection
array$data
DocumentRoot | null$documentRoot
ItemProviderInterface | null$itemProvider
SitemapConfigReaderInterface | null$configReader
\Magento\Sitemap\Model\SitemapItemInterfaceFactory | null$sitemapItemFactory@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 216 of file Sitemap.php.

236  {
237  $this->_escaper = $escaper;
238  $this->_sitemapData = $sitemapData;
239  $documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);
240  $this->_directory = $filesystem->getDirectoryWrite($documentRoot->getPath());
241  $this->_categoryFactory = $categoryFactory;
242  $this->_productFactory = $productFactory;
243  $this->_cmsFactory = $cmsFactory;
244  $this->_dateModel = $modelDate;
245  $this->_storeManager = $storeManager;
246  $this->_request = $request;
247  $this->dateTime = $dateTime;
248  $this->itemProvider = $itemProvider ?: ObjectManager::getInstance()->get(ItemProviderInterface::class);
249  $this->configReader = $configReader ?: ObjectManager::getInstance()->get(SitemapConfigReaderInterface::class);
250  $this->sitemapItemFactory = $sitemapItemFactory ?: ObjectManager::getInstance()->get(
251  \Magento\Sitemap\Model\SitemapItemInterfaceFactory::class
252  );
253  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
254  }
$storeManager
$resource
Definition: bulk.php:12
$filesystem

Member Function Documentation

◆ _addSitemapToRobotsTxt()

_addSitemapToRobotsTxt (   $sitemapFileName)
protected

Add sitemap file to robots.txt

Parameters
string$sitemapFileName
Returns
void
Deprecated:
Because the robots.txt file is not generated anymore, this method is not needed and will be removed in major release.

Definition at line 785 of file Sitemap.php.

786  {
787  $robotsSitemapLine = 'Sitemap: ' . $this->getSitemapUrl($this->getSitemapPath(), $sitemapFileName);
788 
789  $filename = 'robots.txt';
790  $content = '';
791  if ($this->_directory->isExist($filename)) {
792  $content = $this->_directory->readFile($filename);
793  }
794 
795  if (strpos($content, $robotsSitemapLine) === false) {
796  if (!empty($content)) {
797  $content .= $this->_findNewLinesDelimiter($content);
798  }
799  $content .= $robotsSitemapLine;
800  }
801 
802  $this->_directory->writeFile($filename, $content);
803  }
getSitemapUrl($sitemapPath, $sitemapFileName)
Definition: Sitemap.php:759

◆ _construct()

_construct ( )
protected

Init model

Returns
void

Definition at line 261 of file Sitemap.php.

262  {
263  $this->_init(SitemapResource::class);
264  }

◆ _createSitemap()

_createSitemap (   $fileName = null,
  $type = self::TYPE_URL 
)
protected

Create new sitemap file

Parameters
null | string$fileName
string$type
Returns
void
Exceptions
LocalizedException

Definition at line 597 of file Sitemap.php.

598  {
599  if (!$fileName) {
600  $this->_sitemapIncrement++;
601  $fileName = $this->_getCurrentSitemapFilename($this->_sitemapIncrement);
602  }
603 
604  $path = rtrim($this->getSitemapPath(), '/') . '/' . $fileName;
605  $this->_stream = $this->_directory->openFile($path);
606 
607  $fileHeader = sprintf($this->_tags[$type][self::OPEN_TAG_KEY], $type);
608  $this->_stream->write($fileHeader);
609  $this->_fileSize = strlen($fileHeader . sprintf($this->_tags[$type][self::CLOSE_TAG_KEY], $type));
610  }
$type
Definition: item.phtml:13
$fileName
Definition: translate.phtml:15

◆ _createSitemapIndex()

_createSitemapIndex ( )
protected

Generate sitemap index XML file

Returns
void

Definition at line 482 of file Sitemap.php.

483  {
484  $this->_createSitemap($this->getSitemapFilename(), self::TYPE_INDEX);
485  for ($i = 1; $i <= $this->_sitemapIncrement; $i++) {
486  $xml = $this->_getSitemapIndexRow($this->_getCurrentSitemapFilename($i), $this->_getCurrentDateTime());
487  $this->_writeSitemapRow($xml);
488  }
489  $this->_finalizeSitemap(self::TYPE_INDEX);
490  }
_createSitemap($fileName=null, $type=self::TYPE_URL)
Definition: Sitemap.php:597
_getSitemapIndexRow($sitemapFilename, $lastmod=null)
Definition: Sitemap.php:578
_finalizeSitemap($type=self::TYPE_URL)
Definition: Sitemap.php:629
$i
Definition: gallery.phtml:31

◆ _finalizeSitemap()

_finalizeSitemap (   $type = self::TYPE_URL)
protected

Write closing tag and close stream

Parameters
string$type
Returns
void

Definition at line 629 of file Sitemap.php.

630  {
631  if ($this->_stream) {
632  $this->_stream->write(sprintf($this->_tags[$type][self::CLOSE_TAG_KEY], $type));
633  $this->_stream->close();
634  }
635 
636  // Reset all counters
637  $this->_lineCount = 0;
638  $this->_fileSize = 0;
639  }
$type
Definition: item.phtml:13

◆ _getBaseDir()

_getBaseDir ( )
protected

Get base dir

Returns
string

Definition at line 657 of file Sitemap.php.

658  {
659  return $this->_directory->getAbsolutePath();
660  }

◆ _getCurrentDateTime()

_getCurrentDateTime ( )
protected

Get current date time

Returns
string

Definition at line 497 of file Sitemap.php.

498  {
499  return (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
500  }

◆ _getCurrentSitemapFilename()

_getCurrentSitemapFilename (   $index)
protected

Get current sitemap filename

Parameters
int$index
Returns
string

Definition at line 647 of file Sitemap.php.

648  {
649  return str_replace('.xml', '', $this->getSitemapFilename()) . '-' . $this->getStoreId() . '-' . $index . '.xml';
650  }
$index
Definition: list.phtml:44

◆ _getDocumentRoot()

_getDocumentRoot ( )
protected

Get Document root of Magento instance

Returns
string

Definition at line 721 of file Sitemap.php.

722  {
723  return realpath($this->_request->getServer('DOCUMENT_ROOT'));
724  }

◆ _getFormattedLastmodDate()

_getFormattedLastmodDate (   $date)
protected

Get date in correct format applicable for lastmod attribute

Parameters
string$date
Returns
string

Definition at line 707 of file Sitemap.php.

708  {
709  if ($this->lastModMinTsVal === null) {
710  $this->lastModMinTsVal = strtotime(self::LAST_MOD_MIN_VAL);
711  }
712  $timestamp = max(strtotime($date), $this->lastModMinTsVal);
713  return date('c', $timestamp);
714  }

◆ _getMediaUrl()

_getMediaUrl (   $url)
protected

Get media url

Parameters
string$url
Returns
string
Deprecated:
No longer used, as we're generating product image URLs inside collection instead
See also
\Magento\Sitemap\Model\ResourceModel\Catalog\Product::_loadProductImages()

Definition at line 696 of file Sitemap.php.

697  {
698  return $this->_getUrl($url, UrlInterface::URL_TYPE_MEDIA);
699  }
_getUrl($url, $type=UrlInterface::URL_TYPE_LINK)
Definition: Sitemap.php:683

◆ _getSitemapIndexRow()

_getSitemapIndexRow (   $sitemapFilename,
  $lastmod = null 
)
protected

Get sitemap index row

Parameters
string$sitemapFilename
null | string$lastmod
Returns
string

Definition at line 578 of file Sitemap.php.

579  {
580  $url = $this->getSitemapUrl($this->getSitemapPath(), $sitemapFilename);
581  $row = '<loc>' . htmlspecialchars($url) . '</loc>';
582  if ($lastmod) {
583  $row .= '<lastmod>' . $this->_getFormattedLastmodDate($lastmod) . '</lastmod>';
584  }
585 
586  return '<sitemap>' . $row . '</sitemap>';
587  }
getSitemapUrl($sitemapPath, $sitemapFileName)
Definition: Sitemap.php:759

◆ _getSitemapRow()

_getSitemapRow (   $url,
  $lastmod = null,
  $changefreq = null,
  $priority = null,
  $images = null 
)
protected

Get sitemap row

Parameters
string$url
null | string$lastmod
null | string$changefreq
null | string$priority
null | array | \Magento\Framework\DataObject$images
Returns
string Sitemap images
See also
http://support.google.com/webmasters/bin/answer.py?hl=en&answer=178636

Sitemap PageMap

See also
http://support.google.com/customsearch/bin/answer.py?hl=en&answer=1628213

Definition at line 537 of file Sitemap.php.

538  {
539  $url = $this->_getUrl($url);
540  $row = '<loc>' . htmlspecialchars($url) . '</loc>';
541  if ($lastmod) {
542  $row .= '<lastmod>' . $this->_getFormattedLastmodDate($lastmod) . '</lastmod>';
543  }
544  if ($changefreq) {
545  $row .= '<changefreq>' . $changefreq . '</changefreq>';
546  }
547  if ($priority) {
548  $row .= sprintf('<priority>%.1f</priority>', $priority);
549  }
550  if ($images) {
551  // Add Images to sitemap
552  foreach ($images->getCollection() as $image) {
553  $row .= '<image:image>';
554  $row .= '<image:loc>' . htmlspecialchars($image->getUrl()) . '</image:loc>';
555  $row .= '<image:title>' . htmlspecialchars($images->getTitle()) . '</image:title>';
556  if ($image->getCaption()) {
557  $row .= '<image:caption>' . htmlspecialchars($image->getCaption()) . '</image:caption>';
558  }
559  $row .= '</image:image>';
560  }
561  // Add PageMap image for Google web search
562  $row .= '<PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0"><DataObject type="thumbnail">';
563  $row .= '<Attribute name="name" value="' . htmlspecialchars($images->getTitle()) . '"/>';
564  $row .= '<Attribute name="src" value="' . htmlspecialchars($images->getThumbnail()) . '"/>';
565  $row .= '</DataObject></PageMap>';
566  }
567 
568  return '<url>' . $row . '</url>';
569  }
_getUrl($url, $type=UrlInterface::URL_TYPE_LINK)
Definition: Sitemap.php:683

◆ _getStoreBaseDomain()

_getStoreBaseDomain ( )
protected

Get domain from store base url

Returns
string

Definition at line 731 of file Sitemap.php.

732  {
733  $storeParsedUrl = parse_url($this->_getStoreBaseUrl());
734  $url = $storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host'];
735 
736  $documentRoot = trim(str_replace('\\', '/', $this->_getDocumentRoot()), '/');
737  $baseDir = trim(str_replace('\\', '/', $this->_getBaseDir()), '/');
738 
739  if (strpos($baseDir, $documentRoot) === 0) {
740  //case when basedir is in document root
741  $installationFolder = trim(str_replace($documentRoot, '', $baseDir), '/');
742  $storeDomain = rtrim($url . '/' . $installationFolder, '/');
743  } else {
744  //case when documentRoot contains symlink to basedir
745  $url = $this->_getStoreBaseUrl(UrlInterface::URL_TYPE_WEB);
746  $storeDomain = rtrim($url, '/');
747  }
748 
749  return $storeDomain;
750  }
$baseDir
Definition: autoload.php:9

◆ _getStream()

_getStream ( )
protected

Get file handler

Returns
\Magento\Framework\Filesystem\File\WriteInterface
Exceptions
LocalizedException

Definition at line 272 of file Sitemap.php.

273  {
274  if ($this->_stream) {
275  return $this->_stream;
276  } else {
277  throw new LocalizedException(__('File handler unreachable'));
278  }
279  }
__()
Definition: __.php:13

◆ _getUrl()

_getUrl (   $url,
  $type = UrlInterface::URL_TYPE_LINK 
)
protected

Get url

Parameters
string$url
string$type
Returns
string

Definition at line 683 of file Sitemap.php.

684  {
685  return $this->_getStoreBaseUrl($type) . ltrim($url, '/');
686  }
$type
Definition: item.phtml:13

◆ _initSitemapItems()

_initSitemapItems ( )
protected

Initialize sitemap

Returns
void

Definition at line 339 of file Sitemap.php.

340  {
341  $sitemapItems = $this->itemProvider->getItems($this->getStoreId());
342  $mappedItems = $this->mapToSitemapItem();
343  $this->_sitemapItems = array_merge($sitemapItems, $mappedItems);
344 
345  $this->_tags = [
346  self::TYPE_INDEX => [
347  self::OPEN_TAG_KEY => '<?xml version="1.0" encoding="UTF-8"?>' .
348  PHP_EOL .
349  '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' .
350  PHP_EOL,
351  self::CLOSE_TAG_KEY => '</sitemapindex>',
352  ],
353  self::TYPE_URL => [
354  self::OPEN_TAG_KEY => '<?xml version="1.0" encoding="UTF-8"?>' .
355  PHP_EOL .
356  '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' .
357  ' xmlns:content="http://www.google.com/schemas/sitemap-content/1.0"' .
358  ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' .
359  PHP_EOL,
360  self::CLOSE_TAG_KEY => '</urlset>',
361  ],
362  ];
363  }

◆ _isEnabledSubmissionRobots()

_isEnabledSubmissionRobots ( )
protected

Check is enabled submission to robots.txt

Returns
bool
Deprecated:
Because the robots.txt file is not generated anymore, this method is not needed and will be removed in major release.

Definition at line 771 of file Sitemap.php.

772  {
773  $storeId = $this->getStoreId();
774  return (bool)$this->configReader->getEnableSubmissionRobots($storeId);
775  }

◆ _isSplitRequired()

_isSplitRequired (   $row)
protected

Check is split required

Parameters
string$row
Returns
bool

Definition at line 508 of file Sitemap.php.

509  {
510  $storeId = $this->getStoreId();
511  if ($this->_lineCount + 1 > $this->configReader->getMaximumLinesNumber($storeId)) {
512  return true;
513  }
514 
515  if ($this->_fileSize + strlen($row) > $this->configReader->getMaximumFileSize($storeId)) {
516  return true;
517  }
518 
519  return false;
520  }

◆ _writeSitemapRow()

_writeSitemapRow (   $row)
protected

Write sitemap row

Parameters
string$row
Returns
void

Definition at line 618 of file Sitemap.php.

619  {
620  $this->_getStream()->write($row . PHP_EOL);
621  }

◆ addSitemapItem()

addSitemapItem ( DataObject  $sitemapItem)

Add a sitemap item to the array of sitemap items

Parameters
DataObject$sitemapItem
Returns
$this
Deprecated:
100.2.0
See also
ItemProviderInterface

Definition at line 289 of file Sitemap.php.

290  {
291  $this->_sitemapItems[] = $sitemapItem;
292 
293  return $this;
294  }

◆ beforeSave()

beforeSave ( )

Check sitemap file location and permissions

Returns
\Magento\Framework\Model\AbstractModel
Exceptions
LocalizedException

Check path is allow

Check exists and writable path

Check allow filename

Definition at line 371 of file Sitemap.php.

372  {
373  $path = $this->getSitemapPath();
374 
378  if ($path && preg_match('#\.\.[\\\/]#', $path)) {
379  throw new LocalizedException(__('Please define a correct path.'));
380  }
384  if (!$this->_directory->isExist($path)) {
385  throw new LocalizedException(
386  __(
387  'Please create the specified folder "%1" before saving the sitemap.',
388  $this->_escaper->escapeHtml($this->getSitemapPath())
389  )
390  );
391  }
392 
393  if (!$this->_directory->isWritable($path)) {
394  throw new LocalizedException(
395  __('Please make sure that "%1" is writable by the web-server.', $this->getSitemapPath())
396  );
397  }
401  if (!preg_match('#^[a-zA-Z0-9_\.]+$#', $this->getSitemapFilename())) {
402  throw new LocalizedException(
403  __(
404  'Please use only letters (a-z or A-Z), numbers (0-9) or underscores (_) in the filename.'
405  . ' No spaces or other characters are allowed.'
406  )
407  );
408  }
409  if (!preg_match('#\.xml$#', $this->getSitemapFilename())) {
410  $this->setSitemapFilename($this->getSitemapFilename() . '.xml');
411  }
412 
413  $this->setSitemapPath(rtrim(str_replace(str_replace('\\', '/', $this->_getBaseDir()), '', $path), '/') . '/');
414 
415  return parent::beforeSave();
416  }
__()
Definition: __.php:13

◆ getIdentities()

getIdentities ( )

Get unique page cache identities

Returns
array
Since
100.1.5

Implements IdentityInterface.

Definition at line 852 of file Sitemap.php.

853  {
854  return [
855  Value::CACHE_TAG . '_' . $this->getStoreId(),
856  ];
857  }

◆ getSitemapUrl()

getSitemapUrl (   $sitemapPath,
  $sitemapFileName 
)

Get sitemap.xml URL according to all config options

Parameters
string$sitemapPath
string$sitemapFileName
Returns
string

Definition at line 759 of file Sitemap.php.

760  {
761  return $this->_getStoreBaseDomain() . str_replace('//', '/', $sitemapPath . '/' . $sitemapFileName);
762  }

Field Documentation

◆ $_cacheTag

$_cacheTag = true
protected

Definition at line 162 of file Sitemap.php.

◆ $_categoryFactory

$_categoryFactory
protected

Definition at line 124 of file Sitemap.php.

◆ $_cmsFactory

$_cmsFactory
protected

Definition at line 134 of file Sitemap.php.

◆ $_dateModel

$_dateModel
protected

Definition at line 139 of file Sitemap.php.

◆ $_directory

$_directory
protected

Definition at line 102 of file Sitemap.php.

◆ $_escaper

$_escaper
protected

Definition at line 119 of file Sitemap.php.

◆ $_filePath

$_filePath
protected

Definition at line 55 of file Sitemap.php.

◆ $_fileSize

$_fileSize = 0
protected

Definition at line 90 of file Sitemap.php.

◆ $_lineCount

$_lineCount = 0
protected

Definition at line 83 of file Sitemap.php.

◆ $_productFactory

$_productFactory
protected

Definition at line 129 of file Sitemap.php.

◆ $_request

$_request
protected

Definition at line 149 of file Sitemap.php.

◆ $_sitemapData

$_sitemapData
protected

Definition at line 114 of file Sitemap.php.

◆ $_sitemapIncrement

$_sitemapIncrement = 0
protected

Definition at line 69 of file Sitemap.php.

◆ $_sitemapItems

$_sitemapItems = []
protected

Definition at line 62 of file Sitemap.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 144 of file Sitemap.php.

◆ $_stream

$_stream
protected

Definition at line 107 of file Sitemap.php.

◆ $_tags

$_tags = []
protected

Definition at line 76 of file Sitemap.php.

◆ $dateTime

$dateTime
protected

Definition at line 154 of file Sitemap.php.

◆ CLOSE_TAG_KEY

const CLOSE_TAG_KEY = 'end'

Definition at line 37 of file Sitemap.php.

◆ INDEX_FILE_PREFIX

const INDEX_FILE_PREFIX = 'sitemap'

Definition at line 39 of file Sitemap.php.

◆ LAST_MOD_MIN_VAL

const LAST_MOD_MIN_VAL = '0000-01-01 00:00:00'

Last mode date min value

Definition at line 48 of file Sitemap.php.

◆ OPEN_TAG_KEY

const OPEN_TAG_KEY = 'start'

Definition at line 35 of file Sitemap.php.

◆ TYPE_INDEX

const TYPE_INDEX = 'sitemap'

Definition at line 41 of file Sitemap.php.

◆ TYPE_URL

const TYPE_URL = 'url'

Definition at line 43 of file Sitemap.php.


The documentation for this class was generated from the following file: