How to do something after the node is updated in the database? - drupal-7

I want to do something after the node gets updated in the database. I need to be able to hook into the point where the node gets right updated in the database. How can I achieve this?
According to this, I need to find a new hook.

You can use the Rules module, and create a Rule with a code that will execute after create/update/delete. You can also use https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_presave/7 , but this is called before the node is saved.

Why dont you use the rules event After updating exisitng content?

Related

React-Hooks : Listen to Events across independent Components

My App has following sample structure:
<App>
--<Users>
------<UserList/>
--</Users>
--<UserManagement>
------<UserList/>
------<AddUser/>
--</UserManagement>
</App>
In <UserManagement> I use a state variable to listen to the mutation that gets done in <AddUser> so that the <UserList> directly updates after the mutation has been done.
Now if I add a user and go to , the <UserList> there does not re-render as it has no idea about the change in the database. I don't know on what for example a useEffect hook should listen to.
I thought about using React Context provided in <App>. But I'm not sure if this is the right solution. I'm using a simple sqlite database not providing any subscription tools or sth.
Can anybody provide me a hint?
I hope its understandable with this, otherwise I will provide code.
Thanks!
There are two approaches:
you can pass the same state variable in to the component that signifies a change in user list. use the useEffect hook to listen for this variable to get the user list again from the database.
create another state variable in that basically sync up with your database. You pass this variable into the component. when the user is added, you add to the sql database and this variable. You also pass this same variable into to display the users. Keep in mind that this approach basically makes a copy of the user list.

What is the proper way to delete a tree node

import com.codename1.ui.tree.Tree;
import com.codename1.ui.tree.TreeModel;
Upon detecting a delete action from my tree ActionListener,
I delete the path on disk.
FileSystemStorage.getInstance().delete(node.getPath());
Then attempt to refresh the tree where there is one less element in the curr node.
tree.expandPath(true,(Object[]) (node.getNodeParent().getNodesOnPath()));
Can you please provide a working example of delete a single leaf (file) and then refresh the Node Parent
My approach does not work.
If I manually tap on the Node Parent twice, I see the file id no longer displayed as expected.
Thanks in advance.
Once it's shown the tree won't refresh unless you refresh the whole thing. Only hidden nodes take events into account so if you fold and reopen it will update. In the case of deletion you can just use something specific to the file and remove the specific node components from their parents directly which is a bit of a hack.
Alternatively you can refresh the entire tree which is what we do for the GUI builder by setting a new instance of the model. In the GUI builder that's practical because the tree is always expanded. It might be a bit painful for your implementation.

Root Query Create and Delete in Relay.js

I am trying to figure out how to create and delete nodes with Relay where I don't have a parent node. It seems that NODE_DELETE/RANGE_DELETE and RANGE_ADD all require a parent node. Is there a way to perform create and delete mutations from the root query object in Relay.js?
Note: I did find example where creates can be performed with a FIELDS_CHANGE query, but they lack any documentation or reason.
You should be able to use REQUIRED_CHILDREN for this purpose. It's not currently well-documented (or even documented), and it has a somewhat confusing name (as a result, we have a task for renaming it and improving the docs). It will likely be renamed to EXTRA_FRAGMENT in the future.
Normally when you issue a mutation, we perform an intersection between the "fat query" (all the fields that could possibly change as the result of the mutation) and the "tracked query" (all the fields that your app has requested for a node so far, and which should be updated when they change) and we send this query to the server with the mutation.
So, for the use case of creating an entirely new node with no parent, you can specify an identifying field like id in the REQUIRED_CHILDREN, and then use that to, for example, navigate to a view showing the newly-created object. This answer has a very detailed example of how you would do this.
You can pass client:root as the parentID. And then your pathToConnection would be ['client:root', 'someConnection'].
(Tested with Relay Modern. Not sure if this also applies to Relay Classic, but that's officially deprecated now anyways. But this is still one of the top Google results for this issue, so answering.)
(Found in this GitHub issue)

Detaching dynamics $scope

Good day to all.
There is a problem.
Create one object $rootScope.metaContent (need just $rootScope). In the future, to work with the data of the object, creating a new based on the first $scope.addMeta = $rootScope.metaContent. Needless to say, when I'm working with the second (adding an object, change its data or purify) is changed first. But I need to work with the second ($scope.addMeta), that would be the first not changed. It is necessary to restore the data to the source by pressing one button "Undoing".
How can they decouple from each other???
Thanks in advance!!!
You can create a deep copy of an object or an array in angular using angular.copy
$scope.addMeta = angular.copy($rootScope.metaContent);

how to create UISelectItems from a Database

We are in the need of populating UISelectOne- and UISelectMany-Components with SeletItems from a database. Instead of subclassing I decided to create a Child-Component element which is able to provide the SelectItems. This way we dont have to introduce new components for this behavior.
But I cant see whats the best way to do this. At first I thought I just need a TagHandler but it seems that idea was a dead end. I tried to create SelectItems within the apply-method but I dont know how to add the items to the component.
Is there another way. Do I have to create a component instead of a TagHandler?
I might be on the wrong path anyway: as mentioned above, I tried to add the items to the component, but shouldnt this be done by the component-tree automatically.
Any help is appreciated.
but I dont know how to add the items to the component
Just add it as child of the parent component which is already supplied as argument of apply().
parent.getChildren().add(selectItems);

Resources