How Can i add a cloned object to the repository - typo3-9.x

New object is not cloned
$clonedObj = clone $repatNewsObj;
$this->extendednewsRepository->add($clonedObj);
$this->persistenceManager->persistAll();

This is not how you copy an extbase object with TYPO3. Sadly, just cloning it with PHP will not reset the object from the extbase point of view. The add method of the default repository will just ignore the "new" object if it already has a uid in the database. Hence, nothing is actually done by your persist call.
You could either create a new object yourself, setting each property manually, based on the source object or you can use the datahandler to copy your object. There is a blog post describing it (in German) as well as an older SO question discussing the same issue.
If you want to clone an object from one of your own extensions, best practice is to overwrite the __clone method and reset things like uid and so on there. If the model class comes from a third party extension, chose one of the two methods from above.

Related

How to differentiate if a TBO is called when importing new Document vs for any other operations

We are trying to add one additional feature to our method for TBO. The feature needs to be executed only when a new document for that object type is imported and should not be executed in any other case like checkin checkout or any changes in attributes.
However the new code is getting called everytime we make any changes to attribute to that document.
We have put that code in doSave() method.
I tried isNew method for distinguish between newly imported Document and other scenarios, however could not get success, may be missing the usage details of the method.
Can anyone suggest anything?
We are on Documentum version 7.2.
I always use isNew() method to check is object new or versioned, I don't remember having problems with it at any DFC version.
Only one thing that comes in mind is to make sure you don't use super.doSave() while inside the code since right after it method will return false.
But this is expected behaviour.
If you really need to do this - some calulations based on programatically preset data - make sure you use value saved within local variable throughout your code.
If you think you are experiencing bug with the method try with another DFC version or report a bug to the Support.

Notifications when an S3 object is overwritten with versioning ON

Is there a way to configure an S3 bucket to enable notifications/alerts whenever another version of an object is created? I am using versioning to prevent overriding an existing object but I would like also to be able to detect such events.
With versioning, an overwrite will not actually delete the existing object but it well add another object to the same key but with a different version. I would like to configure the bucket to receive a notification only when an object is created on top of another object (again, since we have versioning).

Declaring a "global" object in objective C

I'm creating a social media app, so it follows the basic structure of an app like Twitter. I have a user class that contains a bunch of methods, like loadFeed and postContent. The user class has a few properties, one of which is userID. So basically a user object is created, and the app displays content relevant to that user.
Currently I've only tested by creating the same object in every implementation file. However, I want to create one global object that all the classes can use. How can I do this?
You have few option depends on your requirements.
1. Declare a global variable in a header class.
In your project, press command+N > C and C++ > Header File. Declare a object there. Import this header file in every class you want to use that global object, and use it.
2. Save value in NSUserDefault
Next you can save a variable in a NSUserDefault. It works as same as Session works in web apps, provided, it does not expire automatically.
3. Singleton pattern.
For singleton pattern, you need to have little lengthy processes but this is most memory efficient and best technique. Go through Singletons in Objective-C article

Core Data/Mogenerator - No Getters/Setters Created

I'm using Mogenerator to help with my Core Data implementation and for the most part it works great. However, sometimes when I add new attributes, build, and run the project, I get the following error whenever I try to access the property:
[MyObject myAttribute]: unrecognized selector sent to instance
After looking into the machine generated class, it looks like Mogenerator creates getters/setters for some of my new attributes but not ALL of them. What am I doing wrong? How can I still get/set these new attributes when Mogenerator doesn't give me access to these methods?
What I've tried:
1. Synthesizing each new attribute in my Human generated file (this gets rid of the errors at least, but doesn't actually save anything to Core Data)
2. Writing a custom getter/setter for each missing attribute in my Human generated file (same results as above)
Okay, I forgot to follow rule #1 of resolving computer problems... delete and re-install.
I'm using BitBucket to host my repository so I just deleted my local copy and cloned the project back to my machine. It runs fine now. I'm calling this issue "closed" for now, but any thoughts on why this would happen?

Restore one RCP view while restoring another

Two views in my application need to load same information when restoring state. My idea was, to avoid saving it twice, to have one view create another in init orcreatePartControl if it wasn't created yet. However,
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(...)
doesn't work there, as getActivePage() returns null. Is it possible to work around this?
Delegate to a manager or service to load/maintain/save the shared state. That will ensure the first access initializes your information. When the view is instantiated just go to the manager and retrieve the information. If the user never instantiates your view, then you never had to do the extra work.
In the general case, you can't create/instantiate one view while creating/activating another view. Eclipse won't allow it, and will generate ERRORs in the error log.
EDIT:
3 standard persistence patterns I've seen used (and/or misused :-) are:
1) Have your plugin get its state location and simply serialize you state out there. (location provided for free if you subclass org.eclipse.core.runtime.Plugin) You can do it in your activator stop(BundleContext) method. You can uses classes like org.eclipse.ui.XMLMemento to serialize to/from XML if you don't already have a solution.
2) if you subclass org.eclipse.ui.plugin.AbstractUIPlugin you can use org.eclipse.ui.plugin.AbstractUIPlugin.getDialogSettings() to store your state. Potentially a little bulky as you would have to keep it up to date.
3) have your common manager update a preference, potentially using another serialization technique.