/** * Syncs category object with modx * * @param mixed */ public final function sync() { if (!$this->isSyncable()) { return; } $parent = $this->getParent(); /* @var $category \modCategory */ $category = self::getModX()->getObject('modCategory', array('category' => $this->getName())); if (!$category) { ModSync\Logger::info('Inserting: ' . get_called_class()); $category = self::getModX()->newObject('modCategory'); $category->set('category', $this->getName()); if ($parent) { $category->set('parent', $parent->getId()); } $this->onInsert(); $category->save(); } else { if ($parent && $parent->getId() != $category->get('parent') || !$parent && intval($category->get('parent')) > 0) { ModSync\Logger::info('Updating: ' . get_called_class()); if ($parent) { $category->set('parent', intval($parent->getId())); } else { $category->set('parent', 0); } $this->onUpdate(); $category->save(); } else { ModSync\Logger::debug('No changes to: ' . get_called_class()); } } $this->_id = $category->get('id'); }
/** * Report execution time */ public final function reportProfiling() { if (null !== $this->_profiling && $this->_profiling->enabled) { $this->_profiling->endTime = microtime(); $begin = explode(' ', $this->_profiling->beginTime); $end = explode(' ', $this->_profiling->endTime); $this->_profiling->duration = $end[1] + $end[0] - ($begin[1] + $begin[0]); ModSync\Logger::debug(sprintf(get_called_class() . ': %s (%1.3f seconds)', $this->getName(), $this->_profiling->duration)); if ($this->_profiling->duration > $this->_profiling->threshold) { ModSync\Logger::warn(sprintf(get_called_class() . ': inefficient code - %s (%1.3f seconds)', $this->getName(), $this->_profiling->duration)); } } }
/** * Sync context object */ public final function sync() { if (!$this->isSyncable()) { return $this; } /* @var $context \modContext */ $context = self::getModX()->getObject('modContext', array('key' => $this->getKey())); if ($context) { ModSync\Logger::debug('Already exists: ' . get_called_class()); $this->onUpdate(); } else { ModSync\Logger::info('Inserting: ' . get_called_class()); $context = self::getModX()->newObject('modContext'); $context->set('key', $this->getKey()); $context->set('description', $this->getDescription()); $context->set('rank', (int) $this->_rank); $this->onInsert(); $context->save(); } }
/** * Sync context object */ public final function sync() { if (!$this->isSyncable()) { return; } /* @var $modxElement \modContextSetting */ $modxElement = self::getModX()->getObject('modContextSetting', array('context_key' => $this->getContextKey(), 'key' => $this->getKey(), 'namespace' => $this->getNamespace())); if ($modxElement) { ModSync\Logger::debug('Already exists: ' . get_called_class()); } else { ModSync\Logger::info('Inserting: ' . get_called_class()); $modxElement = self::getModX()->newObject('modContextSetting'); $modxElement->set('context_key', strtolower($this->getContextKey())); $modxElement->set('key', strtolower($this->getKey())); $modxElement->set('namespace', $this->getNamespace()); $modxElement->set('value', $this->getValue()); $modxElement->set('xtype', $this->_xtype); $modxElement->set('area', $this->getArea()); $this->onInsert(); $modxElement->save(); } }
/** * Sync media source */ public final function sync() { if (!$this->isSyncable()) { return; } /* @var $modElement \modMediaSource */ $modElement = self::getModX()->getObject('sources.modMediaSource', array('name' => $this->getName())); if ($modElement) { ModSync\Logger::debug('Already exists: ' . get_called_class()); } else { ModSync\Logger::info('Inserting: ' . get_called_class()); $modElement = self::getModX()->newObject('sources.modMediaSource'); $modElement->set('name', $this->getName()); $modElement->set('description', $this->getDescription()); $modElement->set('class_key', $this->getClassKey()); $this->_properties['basePath']['value'] = 'assets' . DIRECTORY_SEPARATOR . $this->getUrl(); $this->_properties['baseUrl']['value'] = ($this->_relative_url ? '' : '/') . 'assets/' . $this->getUrl(); $this->_properties['baseUrlRelative']['value'] = $this->_relative_url; $modElement->setProperties($this->_properties); @mkdir(self::getAssetsDir() . DIRECTORY_SEPARATOR . trim($this->getUrl(), '/'), 0755, true); $this->onInsert(); $modElement->save(); } }
/** * Syncs an element with modx * * @param string $name Element type * @param array $array Primary key * @return \modElement|false */ protected final function _sync($name, $array) { if (!$this->isSyncable()) { return false; } /* @var $modElement \modElement */ $modElement = self::getModX()->getObject($name, $array); if (!$modElement) { $modElement = self::getModX()->newObject($name, $array); $this->onInsert(); ModSync\Logger::info('Inserting: ' . get_called_class()); } else { if (!$this->_isSyncAllowed($modElement)) { ModSync\Logger::debug('Syncing disabled by user: '******'No changes to: ' . get_called_class()); return false; } $this->onUpdate(); ModSync\Logger::info('Updating: ' . get_called_class()); } if (null === $modElement) { throw new Exception('Trying to sync with null element'); } if ($this instanceof \ModSync\HasContentInterface) { $modElement->setContent($this->getContent()); } if ($this->hasCategory()) { $modElement->set('category', $this->getCategory()->getId()); } $modElement->set('description', $this->getDescription()); $modElement->set('locked', intval($this->_locked)); $modElement->setProperties($this->_properties, true); if ($this->onBeforeSave($modElement) !== false) { $modElement->save(); } return $modElement; }