function beforeDelete($cascade) { // Remove the extended data to be tidy. // First get the type id App::Import('Model', 'Type'); $Type = new Type(); $Type->recursive = -1; $type_record = Set::extract('/Type/id', $Type->find('first', array('fields' => array('Type.id'), 'conditions' => array('Type.alias' => $this->model->data['Node']['type'])))); $type_id = $type_record[0]; // Cool, now find all node schemas App::Import('Model', 'NodeSchema.NodeSchema'); $NodeSchema = new NodeSchema(); $NodeSchema->actsAs = array('Containable'); $schemas = $NodeSchema->find('all', array('fields' => array('NodeSchema.table_name'), 'contains' => array('Type' => array('conditions' => array('Type.id' => $type_id))))); // Now loop through and check for records on those tables to remove if (is_array($schemas) && count($schemas) > 0) { foreach ($schemas as $schema) { $table_name = $schema['NodeSchema']['table_name']; $model = new Model(false, $table_name); $model->primaryKey = 'node_id'; // set the primary key to the node_id if ($model->delete($this->model->data['Node']['id'], false)) { return true; } else { // return false; // There was some sort of error deleting the associated data. Do we even need this? It doesn't redirect, it stops. Have to handle the error. } } } return true; }
public function parse($string) { $xml = $this->SimpleXMLParser->parseXMLString($string, $this->className); $this->validator->validate($xml); $schema = new NodeSchema(); $tags = $this->getTags($xml); foreach ($tags as $tag) { $schema->addTagDef($tag); } $metas = $this->getMetas($xml); foreach ($metas as $meta) { $schema->addMetaDef($meta); } // $sections = $this->getSections($xml); // foreach ( $sections as $section ) // $schema->addSectionDef($section); return $schema; }
/** * Sets the schema for the element * * @param Element $obj The element to analyze * * @return Element the translated element */ public function preCacheTranslateObject(ModelObject $obj) { // merge aspects //$db = $this->getConnection(); // $q = new Query(); // $q->select('aspectid'); // $q->from('elementaspectrel'); // $q->where("elementid = {$db->quote($obj->{$obj->getPrimaryKey()})}"); // $aspectIDs = $db->readCol($q); // $this->populateRels(); // $aspectSlugs = array_key_exists($obj->Slug, $this->aspectrel)?$this->aspectrel[$obj->Slug]['Aspects']:array(); $aspectSlugs = $obj->getAspectSlugs(); $schema = new NodeSchema(); if (!empty($aspectSlugs)) { $aspects = $this->AspectDAO->multiGetBySlug($aspectSlugs); $newAspects = array(); foreach ($aspects as $aspect) { // $plugin = $this->PluginService->getByID($aspect['PluginID']); // if(empty($plugin) || !$plugin->isInstalled() || !$plugin->isEnabled()) // continue; $aspectSchema = $aspect->getSchema(); foreach ($aspectSchema->getTagDefs() as $tagDef) { $schema->addTagDef($tagDef); } foreach ($aspectSchema->getMetaDefs() as $metaDef) { $schema->addMetaDef($metaDef); } $newAspects[] = $aspect; } $obj->setAspects($newAspects); } $obj->setSchema($schema); $obj->setAnchoredSite($this->SiteService->getAnchoredSite()); $obj->setAnchoredSiteSlug($obj->getAnchoredSite()->getSlug()); return $obj; }
private static function isTagRoleInScope(NodeSchema $schema, $partials_string, $role) { $role = strtolower(ltrim($role, '#')); if (empty($partials_string)) { return false; } else { $partials = self::unserializePartials('tags', $partials_string); $all = false; $allfieldlike = false; if ($partials == 'all' || ($x = array_search('all', $partials)) !== false) { $all = true; } else { if (($x = array_search('fields', $partials)) !== false) { $allfieldlike = true; unset($partials[$x]); } } try { $tagDef = $schema->getTagDef($role); } catch (SchemaException $se) { return false; } if ($all) { return true; } if ($allfieldlike && $tagDef->isFieldlike()) { return true; } $inScope = false; foreach ($partials as $partial) { if ($partial->getTagRole() == strtolower($role)) { return true; } } } return false; }
protected function validateTagPartials($direction, $partials_string, $tags, NodeSchema $schema) { if (empty($partials_string)) { if (count($tags) > 0) { $this->Logger->debug('Removing all out-of-scope tags.'); return array(); //$this->getErrors()->reject(ucfirst($direction) . " tags specified, even though none are in scope."); } } else { switch ($direction) { case 'in': $partials = PartialUtils::unserializeInPartials($partials_string); break; case 'out': $partials = PartialUtils::unserializeOutPartials($partials_string); break; default: throw new Exception("Unknown direction {$direction} for partials."); } $all = false; $allfieldlike = false; if ($partials == 'all' || ($x = array_search('all', $partials)) !== false) { $all = true; } else { if (($x = array_search('fields', $partials)) !== false) { $allfieldlike = true; unset($partials[$x]); } } foreach ($tags as $k => $tag) { $id = $tag->getTagRole(); if (empty($id)) { throw new Exception(ucfirst($direction) . " Tag passed without a TagRole"); } $tagDef = $schema->getTagDef($id); if ($all) { continue; } if ($allfieldlike && $tagDef->isFieldlike()) { continue; } $inScope = false; foreach ($partials as $partial) { if ($this->TagsHelper->matchPartial($partial, $tag)) { $inScope = true; break; } } if (!$inScope) { $this->Logger->debug('Silently removing out-of-scope tag: ' . $tag->toString()); unset($tags[$k]); } // $this->getErrors()->reject(ucfirst($direction) ." Tag: " . $tag->toString() . ' is out of scope.'); } } return $tags; }
protected function convertMeta(Node $node, NodeSchema &$schema, Errors &$errors, $name, $value, $rawValue) { $meta_def = $schema->getMetaDef($name); $validation = $meta_def->Validation->getValidationArray(); $key = $meta_def->Id; $fieldTitle = $meta_def->Title; try { $value = $this->TypeConverter->convertFromString($meta_def->Validation, $value, $rawValue); } catch (TypeConversionException $tce) { $errors->addFieldError('invalid', $this->NodeValidator->resolveField($node->getNodeRef(), $key), 'field', $fieldTitle, $value, $tce->getMessage()); } return $value; }