Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with versioned data objects? #8

Open
MattyBalaam opened this issue May 16, 2017 · 1 comment
Open

Doesn't work with versioned data objects? #8

MattyBalaam opened this issue May 16, 2017 · 1 comment

Comments

@MattyBalaam
Copy link

MattyBalaam commented May 16, 2017

I noticed that this didn't appear to work with versioning.

I hacked something together, but this shares some parts with the onBeforeWrite code and could do with a nice refactor, but should be a start, or a help to someone else coming across the same issue.

	public function onBeforePublish($original) {
			$toPublish = array();
	
    		if ($this->owner->toMap()) foreach($this->owner->toMap() as $name => $value) {
	
    			if(!strpos($name, self::separator)) {
	    			// Also skip $name that starts with a separator
		    		continue;
				}
	
    			list($hasone, $key) = explode(self::separator, $name, 2);
	    		if($this->owner->has_one($hasone) || $this->owner->belongs_to($hasone)) {
		    		$rel = $this->owner->getComponent($hasone);
					$rel->setCastedField($key, $value);
    				$toPublish[$hasone] = $rel;
	    		}
			}
	
    		foreach($toPublish as $rel => $obj) {
	    		if ($obj->hasMethod('publish') ) {
		    		$obj->write($this->owner);
			    	$obj->publish('Stage', 'Live');
				}
	
    			$key = $rel . 'ID';
	    		if(!$this->owner->$key) {
		    		$this->owner->$key = $obj->ID;
    			}
			}
    }
@hchokshi
Copy link
Contributor

@MattyBalaam might be an unnecessary necro, but this should be accomplished by setting private static $owns = [] on the parent object, which will publish relations on publish.

obj63mc added a commit to obj63mc/hasoneedit that referenced this issue Jun 28, 2023
With SS5 and the new MAILER_DSN environment variable, when set we are receiving the following error - 

        Fatal error: Uncaught MJS\TopSort\CircularDependencyException: Circular dependency found: modelascontrollercatchallroute->hasoneedit->mailer-dsn-env->hasoneedit in /Users/joemadden/Sites/rumchata/vendor/marcj/topsort/src/CircularDependencyException.php:34 Stack trace: #0 /Users/joemadden/Sites/rumchata/vendor/marcj/topsort/src/Implementations/BaseImplementation.php(57): MJS\TopSort\CircularDependencyException::create(Array) #1 /Users/joemadden/Sites/rumchata/vendor/marcj/topsort/src/Implementations/ArraySort.php(63): MJS\TopSort\Implementations\BaseImplementation->throwCircularExceptionIfNeeded(Object(stdClass), Array) stevie-mayhew#2 /Users/joemadden/Sites/rumchata/vendor/marcj/topsort/src/Implementations/ArraySort.php(75): MJS\TopSort\Implementations\ArraySort->visit(Object(stdClass), Array) stevie-mayhew#3 /Users/joemadden/Sites/rumchata/vendor/marcj/topsort/src/Implementations/ArraySort.php(75): MJS\TopSort\Implementations\ArraySort->visit(Object(stdClass), Array) stevie-mayhew#4 /Users/joemadden/Sites/rumchata/vendor/marcj/topsort/src/Implementations/ArraySort.php(75): MJS\TopSort\Implementations\ArraySort->visit(Object(stdClass), Array) stevie-mayhew#5 /Users/joemadden/Sites/rumchata/vendor/marcj/topsort/src/Implementations/ArraySort.php(115): MJS\TopSort\Implementations\ArraySort->visit(Object(stdClass), Array) stevie-mayhew#6 /Users/joemadden/Sites/rumchata/vendor/marcj/topsort/src/Implementations/ArraySort.php(98): MJS\TopSort\Implementations\ArraySort->doSort() stevie-mayhew#7 /Users/joemadden/Sites/rumchata/vendor/silverstripe/config/src/Transformer/YamlTransformer.php(517): MJS\TopSort\Implementations\ArraySort->sort() stevie-mayhew#8 /Users/joemadden/Sites/rumchata/vendor/silverstripe/config/src/Transformer/YamlTransformer.php(104): SilverStripe\Config\Transformer\YamlTransformer->getSortedYamlDocuments() stevie-mayhew#9 /Users/joemadden/Sites/rumchata/vendor/silverstripe/config/src/Collections/MemoryConfigCollection.php(73): SilverStripe\Config\Transformer\YamlTransformer->transform(Object(SilverStripe\Config\Collections\MemoryConfigCollection)) stevie-mayhew#10 /Users/joemadden/Sites/rumchata/vendor/silverstripe/framework/src/Core/Config/CoreConfigFactory.php(89): SilverStripe\Config\Collections\MemoryConfigCollection->transform(Array) stevie-mayhew#11 /Users/joemadden/Sites/rumchata/vendor/silverstripe/framework/src/Core/Config/CoreConfigFactory.php(67): SilverStripe\Core\Config\CoreConfigFactory->createCore() stevie-mayhew#12 [internal function]: SilverStripe\Core\Config\CoreConfigFactory->SilverStripe\Core\Config\{closure}() stevie-mayhew#13 /Users/joemadden/Sites/rumchata/vendor/silverstripe/config/src/Collections/CachedConfigCollection.php(139): call_user_func(Object(Closure)) stevie-mayhew#14 /Users/joemadden/Sites/rumchata/vendor/silverstripe/config/src/Collections/CachedConfigCollection.php(88): SilverStripe\Config\Collections\CachedConfigCollection->getCollection() stevie-mayhew#15 /Users/joemadden/Sites/rumchata/vendor/silverstripe/framework/src/Core/Config/Config_ForClass.php(81): SilverStripe\Config\Collections\CachedConfigCollection->get('SilverStripe\\Co...', 'module_priority', 1) stevie-mayhew#16 /Users/joemadden/Sites/rumchata/vendor/silverstripe/framework/src/Core/Config/Config_ForClass.php(114): SilverStripe\Core\Config\Config_ForClass->get('module_priority', 1) stevie-mayhew#17 /Users/joemadden/Sites/rumchata/vendor/silverstripe/framework/src/Core/Manifest/ModuleManifest.php(232): SilverStripe\Core\Config\Config_ForClass->uninherited('module_priority') stevie-mayhew#18 /Users/joemadden/Sites/rumchata/vendor/silverstripe/framework/src/Core/BaseKernel.php(200): SilverStripe\Core\Manifest\ModuleManifest->sort() stevie-mayhew#19 /Users/joemadden/Sites/rumchata/vendor/silverstripe/framework/src/Core/CoreKernel.php(32): SilverStripe\Core\BaseKernel->bootManifests(true) stevie-mayhew#20 /Users/joemadden/Sites/rumchata/vendor/silverstripe/framework/src/Control/HTTPApplication.php(132): SilverStripe\Core\CoreKernel->boot(true) stevie-mayhew#21 /Users/joemadden/Sites/rumchata/vendor/silverstripe/framework/src/Control/Middleware/HTTPMiddlewareAware.php(65): SilverStripe\Control\HTTPApplication->SilverStripe\Control\{closure}(Object(SilverStripe\Control\HTTPRequest)) stevie-mayhew#22 /Users/joemadden/Sites/rumchata/vendor/silverstripe/framework/src/Control/HTTPApplication.php(130): SilverStripe\Control\HTTPApplication->callMiddleware(Object(SilverStripe\Control\HTTPRequest), Object(Closure)) stevie-mayhew#23 /Users/joemadden/Sites/rumchata/vendor/silverstripe/framework/src/Control/HTTPApplication.php(113): SilverStripe\Control\HTTPApplication->execute(Object(SilverStripe\Control\HTTPRequest), Object(Closure), true) stevie-mayhew#24 /Users/joemadden/Sites/rumchata/public/index.php(25): SilverStripe\Control\HTTPApplication->handle(Object(SilverStripe\Control\HTTPRequest)) stevie-mayhew#25 {main} thrown in /Users/joemadden/Sites/rumchata/vendor/marcj/topsort/src/CircularDependencyException.php on line 34

When we remove the After clause this then runs as expected.
obj63mc added a commit to obj63mc/hasoneedit that referenced this issue Jun 28, 2023
Currently when set to After: framework/* we are getting an error whenever the MAILER_DSN environment variable is set.

Updating this to just After: framework seems to resolve the issue.

Error we were getting was the following - 
		Fatal error: Uncaught MJS\TopSort\CircularDependencyException: Circular dependency found: modelascontrollercatchallroute->hasoneedit->mailer-dsn-env->hasoneedit in /vendor/marcj/topsort/src/CircularDependencyException.php:34 Stack trace: 
		#0 /vendor/marcj/topsort/src/Implementations/BaseImplementation.php(57): MJS\TopSort\CircularDependencyException::create(Array) 
		#1 /vendor/marcj/topsort/src/Implementations/ArraySort.php(63): MJS\TopSort\Implementations\BaseImplementation->throwCircularExceptionIfNeeded(Object(stdClass), Array) 
		stevie-mayhew#2 /vendor/marcj/topsort/src/Implementations/ArraySort.php(75): MJS\TopSort\Implementations\ArraySort->visit(Object(stdClass), Array) 
		stevie-mayhew#3 /vendor/marcj/topsort/src/Implementations/ArraySort.php(75): MJS\TopSort\Implementations\ArraySort->visit(Object(stdClass), Array) 
		stevie-mayhew#4 /vendor/marcj/topsort/src/Implementations/ArraySort.php(75): MJS\TopSort\Implementations\ArraySort->visit(Object(stdClass), Array) 
		stevie-mayhew#5 /vendor/marcj/topsort/src/Implementations/ArraySort.php(115): MJS\TopSort\Implementations\ArraySort->visit(Object(stdClass), Array) 
		stevie-mayhew#6 /vendor/marcj/topsort/src/Implementations/ArraySort.php(98): MJS\TopSort\Implementations\ArraySort->doSort() 
		stevie-mayhew#7 /vendor/silverstripe/config/src/Transformer/YamlTransformer.php(517): MJS\TopSort\Implementations\ArraySort->sort() 
		stevie-mayhew#8 /vendor/silverstripe/config/src/Transformer/YamlTransformer.php(104): SilverStripe\Config\Transformer\YamlTransformer->getSortedYamlDocuments() 
		stevie-mayhew#9 /vendor/silverstripe/config/src/Collections/MemoryConfigCollection.php(73): SilverStripe\Config\Transformer\YamlTransformer->transform(Object(SilverStripe\Config\Collections\MemoryConfigCollection)) 
		stevie-mayhew#10 /vendor/silverstripe/framework/src/Core/Config/CoreConfigFactory.php(89): SilverStripe\Config\Collections\MemoryConfigCollection->transform(Array) 
		stevie-mayhew#11 /vendor/silverstripe/framework/src/Core/Config/CoreConfigFactory.php(67): SilverStripe\Core\Config\CoreConfigFactory->createCore() 
		stevie-mayhew#12 [internal function]: SilverStripe\Core\Config\CoreConfigFactory->SilverStripe\Core\Config\{closure}() 
		stevie-mayhew#13 /vendor/silverstripe/config/src/Collections/CachedConfigCollection.php(139): call_user_func(Object(Closure)) 
		stevie-mayhew#14 /vendor/silverstripe/config/src/Collections/CachedConfigCollection.php(88): SilverStripe\Config\Collections\CachedConfigCollection->getCollection() 
		stevie-mayhew#15 /vendor/silverstripe/framework/src/Core/Config/Config_ForClass.php(81): SilverStripe\Config\Collections\CachedConfigCollection->get('SilverStripe\\Co...', 'module_priority', 1) 
		stevie-mayhew#16 /vendor/silverstripe/framework/src/Core/Config/Config_ForClass.php(114): SilverStripe\Core\Config\Config_ForClass->get('module_priority', 1) 
		stevie-mayhew#17 /vendor/silverstripe/framework/src/Core/Manifest/ModuleManifest.php(232): SilverStripe\Core\Config\Config_ForClass->uninherited('module_priority') 
		stevie-mayhew#18 /vendor/silverstripe/framework/src/Core/BaseKernel.php(200): SilverStripe\Core\Manifest\ModuleManifest->sort() 
		stevie-mayhew#19 /vendor/silverstripe/framework/src/Core/CoreKernel.php(32): SilverStripe\Core\BaseKernel->bootManifests(true) 
		stevie-mayhew#20 /vendor/silverstripe/framework/src/Control/HTTPApplication.php(132): SilverStripe\Core\CoreKernel->boot(true) 
		stevie-mayhew#21 /vendor/silverstripe/framework/src/Control/Middleware/HTTPMiddlewareAware.php(65): SilverStripe\Control\HTTPApplication->SilverStripe\Control\{closure}(Object(SilverStripe\Control\HTTPRequest)) 
		stevie-mayhew#22 /vendor/silverstripe/framework/src/Control/HTTPApplication.php(130): SilverStripe\Control\HTTPApplication->callMiddleware(Object(SilverStripe\Control\HTTPRequest), Object(Closure)) 
		stevie-mayhew#23 /vendor/silverstripe/framework/src/Control/HTTPApplication.php(113): SilverStripe\Control\HTTPApplication->execute(Object(SilverStripe\Control\HTTPRequest), Object(Closure), true) 
		stevie-mayhew#24 /public/index.php(25): SilverStripe\Control\HTTPApplication->handle(Object(SilverStripe\Control\HTTPRequest)) 
		stevie-mayhew#25 {main} thrown in /vendor/marcj/topsort/src/CircularDependencyException.php on line 34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants