Skip to content

Instantly share code, notes, and snippets.

@Opencontent
Created April 18, 2018 10:48
Show Gist options
  • Save Opencontent/d097c708781c7e2a34236e4d95987446 to your computer and use it in GitHub Desktop.
Save Opencontent/d097c708781c7e2a34236e4d95987446 to your computer and use it in GitHub Desktop.
<?php
/*
Esempio:
cd <ez_doc_root>;
php list_zone_and_block_in_use.php -sbackend --exclude-subtree=541500,595702,515441,165686,212,581893,27411
Restitusce qualcosa simile a:
Zone
10ZonesLayout1
2ZonesLayout1
[...]
Blocchi
CarouselLatestContent
- carousellatestcontent
ItemList
- banners_simple
- itemlist1
[...]
*/
require 'autoload.php';
$cli = eZCLI::instance();
$script = eZScript::instance(array(
'description' => ( "Elenca le zone e i blocchi in uso" ),
'use-session' => false,
'use-modules' => true,
'use-extensions' => true
));
$script->startup();
$options = $script->getOptions(
'[subtree:][exclude-subtree:]',
'',
array(
'subtree' => 'Solo nel subtree selezionato (node_id)',
'exclude-subtree' => 'Ad eccezione dei subtree selezionati (node_id separati da virgola)'
)
);
$script->initialize();
$script->setUseDebugAccumulators(true);
$user = eZUser::fetchByName('admin');
eZUser::setCurrentlyLoggedInUser($user, $user->attribute('contentobject_id'));
$zones = array();
$blockTypes = array();
$subtree = (int)$options['subtree'];
$excludeSubtreeList = explode(',', $options['exclude-subtree']);
$classIdList = eZContentClass::fetchIDListContainingDatatype(eZPageType::DATA_TYPE_STRING);
if ($subtree > 0) {
$cli->error("Cerca nel subtree " . $subtree);
} elseif (!empty($excludeSubtreeList)) {
$cli->error("Esclude i subtree " . implode(' ', $excludeSubtreeList));
}
foreach ($classIdList as $classId) {
$class = eZContentClass::fetch($classId);
$cli->error("Search for " . $class->attribute('name'));
/** @var eZContentObject[] $objects */
$objects = $class->objectList();
foreach ($objects as $object) {
$run = true;
if ($subtree > 0 || !empty($excludeSubtreeList)) {
$assignedNodes = $object->assignedNodes();
foreach ($assignedNodes as $assignedNode) {
$pathString = explode('/', $assignedNode->attribute('path_string'));
if ($subtree > 0) {
$run = in_array($subtree, $pathString);
} elseif (!empty($excludeSubtreeList)) {
foreach ($excludeSubtreeList as $excludeSubtree) {
$run = !in_array($excludeSubtree, $pathString);
if (!$run) {
break;
}
}
}
}
}
if ($run) {
$version = $object->currentVersion();
$availableLanguages = $version->translationList(false, false);
foreach ($availableLanguages as $languageCode) {
/** @var eZContentObjectAttribute[] $dataMap */
$dataMap = $object->fetchDataMap(false, $languageCode);
foreach ($dataMap as $attribute) {
if ($attribute->attribute('data_type_string') == eZPageType::DATA_TYPE_STRING && $attribute->hasContent()) {
/** @var eZPage $page */
$page = $attribute->content();
$zones[] = $page->attribute('zone_layout');
$zones = array_unique($zones);
sort($zones);
/** @var eZPageZone $zone */
foreach ($page->attribute('zones') as $zone) {
/** @var eZPageBlock $block */
foreach ($zone->attribute('blocks') as $block) {
if (!isset($blockTypes[$block->attribute('type')])) {
$blockTypes[$block->attribute('type')] = array();
}
$blockTypes[$block->attribute('type')][] = $block->attribute('view');
$blockTypes[$block->attribute('type')] = array_unique($blockTypes[$block->attribute('type')]);
sort($blockTypes[$block->attribute('type')]);
}
}
}
}
}
}
eZContentObject::clearCache();
}
}
$cli->warning();
$cli->warning("Zone");
foreach ($zones as $zone) {
$cli->output($zone);
}
$cli->warning("Blocchi");
foreach ($blockTypes as $blockType => $views) {
$cli->output($blockType);
foreach ($views as $view) {
$cli->output(' - ' . $view);
}
}
$script->shutdown();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment