function updateClass($classId, $scheduledScript) { $cli = eZCLI::instance(); /* // If the class is not stored yet, store it now $class = eZContentClass::fetch( $classId, true, eZContentClass::VERSION_STATUS_TEMPORARY ); if ( $class ) { $cli->output( "Storing class" ); $class->storeDefined( $class->fetchAttributes() ); } */ // Fetch the stored class $class = eZContentClass::fetch($classId, true, eZContentClass::VERSION_STATUS_MODIFIED); if (!$class) { $cli->error('No class in a modified version status with ID: ' . $classId); return; } // Fetch attributes and definitions $attributes = $class->fetchAttributes($classId, true, eZContentClass::VERSION_STATUS_MODIFIED); $oldClassAttributes = $class->fetchAttributes($classId, true, eZContentClass::VERSION_STATUS_DEFINED); // Delete object attributes which have been removed. foreach ($oldClassAttributes as $oldClassAttribute) { $attributeExist = false; $oldClassAttributeID = $oldClassAttribute->attribute('id'); foreach ($attributes as $newClassAttribute) { if ($oldClassAttributeID == $newClassAttribute->attribute('id')) { $attributeExist = true; } } if (!$attributeExist) { $ezscriptmonitorINI = eZINI::instance('ezscriptmonitor.ini'); $objectLimit = $ezscriptmonitorINI->variable('GeneralSettings', 'ObjectLimit'); $limit = array('offset' => 0, 'length' => $objectLimit); do { $objectAttributes = eZContentObjectAttribute::fetchSameClassAttributeIDList($oldClassAttributeID, false, false, false, $limit); $objectAttributeCount = count($objectAttributes); $conditions = array("contentclassattribute_id" => $oldClassAttributeID); $totalObjectAttributeCount = eZContentObjectAttribute::count(eZContentObjectAttribute::definition(), array("contentclassattribute_id" => $oldClassAttributeID)); if (is_array($objectAttributes) && $objectAttributeCount > 0) { $db = eZDB::instance(); $db->begin(); foreach ($objectAttributes as $objectAttribute) { $objectAttribute = new eZContentObjectAttribute($objectAttribute); $objectAttribute->removeThis($objectAttribute->attribute('id')); } $db->commit(); $limit['offset'] += $objectAttributeCount; $percentage = round(100 * $limit['offset'] / $totalObjectAttributeCount, 2); // for ezscriptmonitor 100 means the script is all the way done if ($percentage < 100 && $scheduledScript !== false) { $scheduledScript->updateProgress($percentage); } $cli->output("Removing attributes - Progress: " . $percentage . " %"); } } while ($objectAttributeCount == $objectLimit); } } $class->storeVersioned($attributes, eZContentClass::VERSION_STATUS_DEFINED); // Add object attributes which have been added. foreach ($attributes as $newClassAttribute) { $attributeExist = false; foreach ($oldClassAttributes as $oldClassAttribute) { if ($oldClassAttribute->attribute('id') == $newClassAttribute->attribute('id')) { $attributeExist = true; break; } } if (!$attributeExist) { $objects = null; $cli->output("Adding attribute : " . $newClassAttribute->attribute('name')); $newClassAttribute->initializeObjectAttributes($objects); } } if ($scheduledScript !== false) { $scheduledScript->updateProgress(100); } }