예제 #1
0
 public function process()
 {
     if (!$this->addLock()) {
         return $this->failure($this->modx->lexicon('resource_locked_by', array('id' => $this->resource->get('id'), 'user' => $this->lockedUser->get('username'))));
     }
     if ($this->isSiteStart()) {
         return $this->failure($this->modx->lexicon('resource_err_unpublish_sitestart'));
     }
     $this->resource->set('published', false);
     $this->resource->set('pub_date', false);
     $this->resource->set('unpub_date', false);
     $this->resource->set('editedby', $this->modx->user->get('id'));
     $this->resource->set('editedon', time(), 'integer');
     $this->resource->set('publishedby', false);
     $this->resource->set('publishedon', false);
     if ($this->resource->save() == false) {
         $this->resource->removeLock();
         return $this->failure($this->modx->lexicon('resource_err_unpublish'));
     }
     $this->fireAfterUnPublishEvent();
     $this->logManagerAction();
     $skipClearCache = $this->getProperty('skipClearCache', false);
     if ($skipClearCache == false) {
         $this->clearCache();
     }
     return $this->success('', $this->resource->get(array('id')));
 }
예제 #2
0
 /**
  * {@inheritDoc}
  * @return mixed
  */
 public function process()
 {
     if ($this->modx->getOption('site_start') == $this->resource->get('id')) {
         return $this->failure($this->modx->lexicon('resource_err_delete_sitestart'));
     }
     if ($this->modx->getOption('site_unavailable_page') == $this->resource->get('id')) {
         return $this->failure($this->modx->lexicon('resource_err_delete_siteunavailable'));
     }
     /* check for locks on resource */
     if (!$this->addLock()) {
         return $this->failure($this->modx->lexicon('resource_locked_by', array('id' => $this->resource->get('id'), 'user' => $this->lockedUser->get('username'))));
     }
     $childrenIds = $this->getChildrenIds();
     $this->fireBeforeDelete($childrenIds);
     /* delete children */
     $this->deleteChildren();
     /* delete the document. */
     $this->resource->set('deleted', true);
     $this->resource->set('deletedby', $this->modx->user->get('id'));
     $this->resource->set('deletedon', $this->deletedTime);
     if ($this->resource->save() == false) {
         $this->resource->removeLock();
         return $this->failure($this->modx->lexicon('resource_err_delete'));
     }
     $this->fireAfterDelete($childrenIds);
     /* log manager action */
     $this->logManagerAction();
     $this->resource->removeLock();
     /* empty cache */
     $this->clearCache();
     return $this->success('', $this->resource->get(array('id', 'deleted', 'deletedby', 'deletedon')));
 }
예제 #3
0
 public function process()
 {
     if (!$this->addLock()) {
         return $this->failure($this->modx->lexicon('resource_locked_by', array('id' => $this->resource->get('id'), 'user' => $this->lockedUser->get('username'))));
     }
     $duplicateAlias = $this->checkForDuplicateAlias();
     if ($duplicateAlias !== false) {
         return $this->failure($duplicateAlias);
     }
     /* publish resource */
     $this->resource->set('published', true);
     $this->resource->set('pub_date', false);
     $this->resource->set('unpub_date', false);
     $this->resource->set('editedby', $this->modx->user->get('id'));
     $this->resource->set('editedon', time(), 'integer');
     $this->resource->set('publishedby', $this->modx->user->get('id'));
     $this->resource->set('publishedon', time());
     $saved = $this->resource->save();
     $this->resource->removeLock();
     if (!$saved) {
         return $this->failure($this->modx->lexicon('resource_err_publish'));
     }
     $this->fireAfterPublish();
     $this->logManagerAction();
     $this->clearCache();
     return $this->success('', $this->resource->get(array('id', 'pub_date', 'unpub_date', 'editedby', 'editedon', 'publishedby', 'publishedon')));
 }
예제 #4
0
 public function process()
 {
     if (!$this->addLock()) {
         return $this->failure($this->modx->lexicon('resource_locked_by', array('id' => $this->resource->get('id'), 'user' => $this->lockedUser->get('username'))));
     }
     /* 'undelete' the resource. */
     $this->resource->set('deleted', false);
     $this->resource->set('deletedby', 0);
     $this->resource->set('deletedon', 0);
     if ($this->resource->save() == false) {
         $this->resource->removeLock();
         return $this->failure($this->modx->lexicon('resource_err_undelete'));
     }
     $this->unDeleteChildren($this->resource->get('id'), $this->resource->get('deletedon'));
     $this->fireAfterUnDeleteEvent();
     /* log manager action */
     $this->logManagerAction();
     /* empty cache */
     $skipClearCache = $this->getProperty('skipClearCache', false);
     if ($skipClearCache == false) {
         $this->clearCache();
     }
     $this->removeLock();
     $deletedCount = $this->modx->getCount('modResource', array('deleted' => 1));
     $outputArray = $this->resource->get(array('id'));
     $outputArray['deletedCount'] = $deletedCount;
     return $this->modx->error->success('', $outputArray);
 }
예제 #5
0
 public function process()
 {
     if (!$this->validate()) {
         return $this->failure();
     }
     $this->resource->fromArray($this->getProperties());
     if ($this->resource->save() === false) {
         return $this->failure($this->modx->lexicon('resource_err_save'));
     }
     return $this->success();
 }
 /**
  * @param \modResource $originalParent
  */
 protected function handleOriginalParent($originalParent)
 {
     $originalGreatParent = $originalParent->Parent;
     if ($originalGreatParent && $originalGreatParent->class_key == 'CollectionContainer' && $originalParent->hasChildren() == 0) {
         $originalParent->set('show_in_tree', 0);
         $originalParent->save();
     }
 }
예제 #7
0
 /**
  * Quick check to make sure it's not site_start, if so, publish if not published to prevent site error
  * 
  * @return boolean
  */
 public function checkIfSiteStart()
 {
     $saved = false;
     if ($this->object->get('id') == $this->workingContext->getOption('site_start') && !$this->object->get('published')) {
         $this->object->set('published', true);
         $saved = $this->object->save();
     }
     return $saved;
 }
 public function save($cacheFlag = null)
 {
     $isNew = $this->isNew();
     $saved = parent::save($cacheFlag);
     if ($saved && !$isNew && !empty($this->oldAlias)) {
         $newAlias = $this->get('alias');
         $saved = $this->updateChildrenURIs($newAlias, $this->oldAlias);
     }
     return $saved;
 }
예제 #9
0
 /**
  * Process this page, load the resource, and present its values
  * @return void
  */
 public function process()
 {
     $data = $this->processInput($this->config['gpc']);
     /* @var modProcessorResponse $response */
     $response = $this->modx->runProcessor('resource/create', $data);
     if (!$response->isError()) {
         $tempRes = $response->getObject();
         $this->resource = $this->modx->getObject('modResource', $tempRes['id']);
         /* Make sure the createdby column is set */
         $cb = $this->resource->get('createdby');
         if (empty($cb)) {
             $this->resource->set('createdby', $this->modx->user->get('id'));
             $this->resource->save();
         }
         $this->setPlaceholders(array('message' => 'Resource created.', 'resid' => $this->resource->get('id'), 'ctx' => $this->resource->get('context_key')));
     } else {
         $error = $response->getAllErrors();
         $this->setPlaceholder('message', 'Something went wrong creating the Resource: ' . implode(', ', $error));
     }
 }
예제 #10
0
 /**
  * Set the parents isfolder status based upon remaining children
  *
  * @TODO Debate whether or not this should be default functionality
  * 
  * @return void
  */
 public function fixParents()
 {
     if (!empty($this->oldParent) && !empty($this->newParent)) {
         $oldParentChildrenCount = $this->modx->getCount('modResource', array('parent' => $this->oldParent->get('id')));
         if ($oldParentChildrenCount <= 0 || $oldParentChildrenCount == null) {
             $this->oldParent->set('isfolder', false);
             $this->oldParent->save();
         }
         $this->newParent->set('isfolder', true);
     }
 }
 /**
  * @param \modResource $parent
  * @param \modResource $resource
  * @param \modResource $originalParent
  */
 protected function handleOriginalParent($parent, $resource, $originalParent)
 {
     if ($originalParent->class_key == 'CollectionContainer') {
         if ($parent->class_key != 'CollectionContainer') {
             $resource->set('show_in_tree', 1);
         }
     } else {
         /** @var \modResource $originalGreatParent */
         $originalGreatParent = $originalParent->Parent;
         if ($originalGreatParent && $originalGreatParent->class_key == 'CollectionContainer') {
             $resource->set('show_in_tree', 1);
             if ($originalParent->hasChildren() == 0) {
                 $originalParent->set('show_in_tree', 0);
                 $originalParent->save();
             }
         }
     }
 }
예제 #12
0
 /**
  * Set the parents isfolder status based upon remaining children
  *
  * @return void
  */
 public function fixParents()
 {
     $autoIsFolder = $this->modx->getOption('auto_isfolder', null, true);
     if (!$autoIsFolder) {
         return;
     }
     if (!empty($this->oldParent)) {
         $oldParentChildrenCount = $this->modx->getCount('modResource', array('parent' => $this->oldParent->get('id')));
         if ($oldParentChildrenCount <= 0 || $oldParentChildrenCount == null) {
             $this->oldParent->set('isfolder', false);
             $this->oldParent->save();
         }
     }
     if (!empty($this->newParent)) {
         $this->newParent->set('isfolder', true);
         $this->newParent->save();
     }
 }
예제 #13
0
 private function saveMarkdown()
 {
     $resourceArray = $this->resource->toArray();
     $mode = $this->sp['mode'];
     $deleteUnused = (int) $this->md->getOption('upload.delete_unused', null, 1);
     $underResource = (int) $this->md->getOption('upload.under_resource', null, 1);
     if ($mode == \modSystemEvent::MODE_UPD) {
         if ($deleteUnused && $underResource) {
             $this->uploadedFiles();
         }
     }
     foreach ($resourceArray as $field => $value) {
         if (!strpos($field, '_markdown')) {
             continue;
         }
         $fieldName = str_replace('_markdown', '', $field);
         $markdown = $this->modx->fromJSON($this->resource->getProperty('markdown', 'markdowneditor', '[]'));
         if ($mode == \modSystemEvent::MODE_NEW) {
             if ($underResource) {
                 $this->moveFilesUnderCorrectResource($value, $fieldName);
             }
         }
         if ($mode == \modSystemEvent::MODE_UPD) {
             if ($deleteUnused && $underResource) {
                 $this->unsetUnusedFiles($value);
             }
         }
         $markdown[$fieldName] = $value;
         $this->resource->setProperty('markdown', $this->modx->toJSON($markdown), 'markdowneditor');
         $this->resource->save();
         $this->resource->{$field} = '';
     }
     if ($mode == \modSystemEvent::MODE_UPD) {
         if ($deleteUnused && $underResource) {
             $this->deleteUnusedFiles();
         }
     }
 }
예제 #14
0
 /**
  * We override/enhance the parent save() operation so we can cache the 
  * hierarchical data in there as the terms are manipulated.
  *
  * properties is rendered as JSON -- see notes @ top of class for structure.
  *
  * Updating a term triggers a ripple UP the tree.
  * Moving a term up/down in the hierarchy forces an unsetting in prev_parent
  */
 public function save($cacheFlag = null)
 {
     $properties = $this->get('properties');
     $fingerprint = $this->xpdo->getOption('fingerprint', $properties);
     // the old one
     $prev_parent = $this->xpdo->getOption('prev_parent', $properties);
     $children = $this->xpdo->getOption('children', $properties, array());
     $properties['fingerprint'] = $this->_calc_fingerprint();
     // the new one
     $properties['prev_parent'] = $this->get('parent');
     $this->set('properties', $properties);
     $rt = parent::save($cacheFlag);
     // <-- the normal save
     // old == new ?
     if ($fingerprint == $properties['fingerprint']) {
         $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, $this->get('id') . ': Fingerprint unchanged. No action taken.', '', __CLASS__, basename(__FILE__), __LINE__);
         $rt = parent::save($cacheFlag);
         return $rt;
         // nothing to do
     }
     $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'New Fingerprint detected.', $this->get('id'), __CLASS__, basename(__FILE__), __LINE__);
     // moved?  Run unset on prev_parent to remove this term as a child
     if ($prev_parent != $this->get('parent')) {
         $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, $this->get('id') . ': Move in the hierarchy detected from ' . $prev_parent . ' to ' . $this->get('parent'), '', __CLASS__, basename(__FILE__), __LINE__);
         $PrevParent = $this->xpdo->getObject('modResource', $prev_parent);
         if ($PrevParent) {
             $prev_parent_props = $PrevParent->get('properties');
             unset($prev_parent_props['children'][$this->get('id')]);
             unset($prev_parent_props['children_ids'][$this->get('id')]);
             $PrevParent->set('properties', $prev_parent_props);
             if (!$PrevParent->save()) {
                 // <-- this may ripple up
                 $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, $this->get('id') . ': Error saving previous parent ' . $prev_parent, '', __CLASS__, basename(__FILE__), __LINE__);
             }
         }
     }
     $Parent = $this->xpdo->getObject('modResource', $this->get('parent'));
     if (!$Parent) {
         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Parent not found!', $this->get('id'), __CLASS__, basename(__FILE__), __LINE__);
         return $rt;
         // nothing we can do
     }
     $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, $this->get('id') . ': Updating the parent (' . $this->get('parent') . ')', '', __CLASS__, basename(__FILE__), __LINE__);
     $parent_props = $Parent->get('properties');
     // Children may be out of date by this point
     $parent_props['children'][$this->get('id')] = array('alias' => $this->get('alias'), 'pagetitle' => $this->get('pagetitle'), 'published' => $this->get('published'), 'menuindex' => $this->get('menuindex'), 'children' => $children);
     $parent_props['children_ids'][$this->get('id')] = true;
     $Parent->set('properties', $parent_props);
     if (!$Parent->save()) {
         // <-- this may ripple up
         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $this->get('id') . ': Error saving parent ' . $this->get('parent'), '', __CLASS__, basename(__FILE__), __LINE__);
     }
     return $rt;
 }
예제 #15
0
 /**
  * @param null $cacheFlag
  *
  * @return bool
  */
 public function save($cacheFlag = null)
 {
     $this->set('isfolder', 1);
     $update_actions = false;
     if ($properties = parent::get('properties')) {
         if (!empty($properties['ratings'])) {
             $ratings = implode(array_values($properties['ratings']));
             $update_actions = !empty($this->_oldRatings) && $this->_oldRatings != $ratings;
         }
     }
     $new = $this->isNew();
     $saved = parent::save($cacheFlag);
     if ($saved && !$new) {
         $this->updateChildrenURIs();
     }
     if ($saved && $update_actions) {
         $this->updateAuthorsActions();
     }
     return $saved;
 }
예제 #16
0
    /**
     * @param modManagerController $controller
     * @param modResource $resource
     */
    public function loadManagerFiles(modManagerController $controller, modResource $resource)
    {
        $modx23 = (int) $this->systemVersion();
        $cssUrl = $this->config['cssUrl'] . 'mgr/';
        $jsUrl = $this->config['jsUrl'] . 'mgr/';
        $properties = $resource->getProperties('ms2gallery');
        if (empty($properties['media_source'])) {
            if (!($source_id = $resource->getTVValue('ms2Gallery'))) {
                /** @var modContextSetting $setting */
                $setting = $this->modx->getObject('modContextSetting', array('key' => 'ms2gallery_source_default', 'context_key' => $resource->get('context_key')));
                $source_id = !empty($setting) ? $setting->get('value') : $this->modx->getOption('ms2gallery_source_default');
            }
            $resource->setProperties(array('media_source' => $source_id), 'ms2gallery');
            $resource->save();
        } else {
            $source_id = $properties['media_source'];
        }
        if (empty($source_id)) {
            $source_id = $this->modx->getOption('ms2gallery_source_default');
        }
        $resource->set('media_source', $source_id);
        $controller->addLexiconTopic('ms2gallery:default');
        $controller->addJavascript($jsUrl . 'ms2gallery.js');
        $controller->addLastJavascript($jsUrl . 'misc/ms2.combo.js');
        $controller->addLastJavascript($jsUrl . 'misc/ms2.utils.js');
        $controller->addLastJavascript($jsUrl . 'misc/plupload/plupload.full.js');
        $controller->addLastJavascript($jsUrl . 'misc/ext.ddview.js');
        $controller->addLastJavascript($jsUrl . 'gallery.view.js');
        $controller->addLastJavascript($jsUrl . 'gallery.window.js');
        $controller->addLastJavascript($jsUrl . 'gallery.toolbar.js');
        $controller->addLastJavascript($jsUrl . 'gallery.panel.js');
        $controller->addCss($cssUrl . 'main.css');
        if (!$modx23) {
            $controller->addCss($cssUrl . 'font-awesome.min.css');
        }
        $source_config = array();
        /** @var modMediaSource $source */
        if ($source = $this->modx->getObject('modMediaSource', $source_id)) {
            $tmp = $source->getProperties();
            foreach ($tmp as $v) {
                $source_config[$v['name']] = $v['value'];
            }
        }
        $controller->addHtml('
		<script type="text/javascript">
			MODx.modx23 = ' . $modx23 . ';
			ms2Gallery.config = ' . $this->modx->toJSON($this->config) . ';
			ms2Gallery.config.media_source = ' . $this->modx->toJSON($source_config) . ';
		</script>');
        if ($this->modx->getOption('ms2gallery_new_tab_mode', null, true)) {
            $controller->addLastJavascript($jsUrl . 'tab.js');
        } else {
            $insert = '
				tabs.add({
					xtype: "ms2gallery-page",
					id: "ms2gallery-page",
					title: _("ms2gallery"),
					record: {
						id: ' . $resource->get('id') . ',
						source: ' . $source_id . ',
					}
				});
			';
            if ($this->modx->getCount('modPlugin', array('name' => 'AjaxManager', 'disabled' => false))) {
                $controller->addHtml('
				<script type="text/javascript">
					Ext.onReady(function() {
						window.setTimeout(function() {
							var tabs = Ext.getCmp("modx-resource-tabs");
							if (tabs) {
								' . $insert . '
							}
						}, 10);
					});
				</script>');
            } else {
                $controller->addHtml('
				<script type="text/javascript">
					Ext.ComponentMgr.onAvailable("modx-resource-tabs", function() {
						var tabs = this;
						tabs.on("beforerender", function() {
							' . $insert . '
						});
					});
				</script>');
            }
        }
    }
예제 #17
0
 /**
  * @param null $cacheFlag
  *
  * @return bool
  */
 public function save($cacheFlag = null)
 {
     $action = $this->isNew() || $this->isDirty('deleted') || $this->isDirty('published');
     $enabled = $this->get('published') && !$this->get('deleted');
     $isNew = $this->isNew();
     $new_parent = $this->isDirty('parent');
     $new_author = $this->isDirty('createdby');
     if ($new_parent || $this->isDirty('alias') || $this->isDirty('published') || $this->get('uri_override') && !$this->get('uri')) {
         $this->setUri($this->get('alias'));
     }
     $save = parent::save();
     /** @var TicketAuthor $profile */
     if ($new_author && ($profile = $this->xpdo->getObject('TicketAuthor', $this->_oldAuthor))) {
         $profile->removeAction('ticket', $this->id, $this->get('createdby'));
     }
     if ($profile = $this->xpdo->getObject('TicketAuthor', $this->get('createdby'))) {
         if (($action || $new_author) && $enabled) {
             $profile->addAction('ticket', $this->id, $this->id);
         } elseif (!$enabled) {
             $profile->removeAction('ticket', $this->id, $this->get('createdby'));
         }
     }
     if ($new_parent && !$isNew) {
         $this->updateAuthorsActions();
     }
     return $save;
 }
예제 #18
0
 /**
  * {@inheritdoc}
  */
 public function save($cacheFlag = null)
 {
     $res = parent::save($cacheFlag);
     if (!is_object($this->data)) {
         $this->loadData();
     }
     $this->setProductOptions($this->data);
     $this->data->set('id', parent::get('id'));
     $this->data->save($cacheFlag);
     return $res;
 }