how to delete dummy content generated by Generate items? - drupal

Is it allowed to ask questions about Drupal here?
I assume the answer is "yes" and ask my question.
I used Generate items (a part of the Devel module) to generate some dummy content, but I can not find any option to delete them.
How can I delete them from my database?

Go to /admin/content/node, select them, and select "Delete selected"

Have you tried using Views Bulk Operations module: http://drupal.org/project/views_bulk_operations ?

When you create content you have an option "Delete all content in these node types before generating new content." If you check it and set the nodes to be generated to 0, it will only delete the nodes of the selected type without generating new ones. However, this will also delete nodes not created by devel.
According to Devel authors, Devel module is not going to keep track of its generated content, so you have to use something else, like views bulk operations or delete_all modules.

Related

How to remove traces of Fields that belonged to a module content type?

I am trying to learn how to create a custom content type programmatically from within my module.
However, after uninstalling and reinstalling my module I was getting an error stating that one or more of the fields I was trying to create could not be created because they already exist.
So I went hacking through my databse, removing the content type and all tables that belonged to it.
Same result -- field already exists.
Next I went to the Drupal API website looking for ways to delete fields and field instances, and came across
field_delete_field()
and
field_delete_instance()
I made a php page to try to delete the fields that I had created, only to get an error stating that the table I was trying to delete does not exist.
So I'm kinda stuck -- I can't create the fields because they already exist, and I can't delete them because they don't exist!
BTW the code I was modeling my module after is the code found in the "node_example" section of the Drupal examples module.
Ouch, deleting the database tables manually is never a good idea - Drupal's not that forgiving :)
Just to address the code in your install/enable hook, wrap the field creation in:
if (!field_info_field('field_name')) {
field_create_field(...
}
That will stop the problem happening again. Or if you don't want to do that, make sure the field is deleted in the uninstall/disable hook. Obviously that method would potentially result in data loss.
To address the current problem, follow this process:
Completely uninstall (not just disable) your custom module. If it's in an inconsistent state, just delete its row in the system table.
Delete all traces of the field from the field_config and field_config_instance tables.
Truncate all the cache tables manually (any table beginning with cache_).
Not strictly necessary but clear up any lingering content:
$nids = db_query('SELECT nid FROM {node} WHERE type = :type', array(':type' => 'type'))->fetchCol();
node_delete_multiple($nids);
That ought to do it.
Any time you delete a field, through the UI or programatically you'll need to either run cron or call field_purge_batch() to 'hard' delete the fields as they're only marked for deletion in the first instance.

How to add/save temporary table on form

We created special form to creating purchase prices for vendors.
New form has almost the same fields as original (so we used PriceDiscTable), but the record/datasoruce was set as temporary table. After user filled mandatory fields will click button, (extra logic behind) and record will inster to database (real priceDiscTable).
The idea was to grand access to trade prices for users that not necessarily has access to purchase prices. In theory everything was ok, but when user with no access to PriceDiscTable open new form, error was shown "Not enougt right to use table 'Price agreements'".
We try set the AllowCheck to false in formDatasource but this only allow us to open the form, but user still cannot add or modify records.
Is there any way to force system to allow user to write data in the temporary table?
Disabling security key or grand access to real table is not an option.
Duplicate table and create with same fields is nuisance (if we use same table we can use data() method to assign fields)
I think that creating a new temporary table with [almost] the same fields would be the best solution.
If the only reason you oppose to this approach is that you wouldn't be able to use data() to copy data from one table to another you can use buf2BufByName() as described here: http://mybhat.blogspot.co.uk/2012/07/dynamics-ax-buf2buf-and-buf2bufbyname.html
You can use RunAs to impersonate another user...perhaps a system user. I don't entirely follow what you are trying to do, but it sounds like this solution would work for you if you know exactly what your custom code is doing and is capable of.
See Classes\AifOutboundProcessingService\runAsWrapper to see an example.
You will not be able to display the PriceDiscTable without giving the user at least "view" access or editing Classes\FormRun to somehow bypass the security key, which is kernel level so it's also not possible.
I agree with 10p where you should create a temp table and then create a custom method handler combined with buf2bufbyname() or buf2buf().
Another option you can screw around with, if you REALLY want to use .data() is using a Common as the datasource. You could add the fields you want on the grid with the common, then you can pass a common back/forth. This has a good amount of form setup to get this working, but it could produce what you want eventually I think.
static void Job8(Args _args)
{
Common common;
salesTable salesTable;
;
common = new DictTable(366).makeRecord();
select firstonly common where common.RecId == 5637145357;
salesTable.data(common);
info(strfmt("%1 - %2", salesTable.SalesId, salesTable.SalesName));
}

Bulk update of Drupal 7 taxonomy terms

My Drupal 7 site has a bit redundant taxonomy structure with taxonomy terms "Article" and "Document" being used synonymously. Hence a large number (several hundreds) of nodes has both "Article" and "Document" terms applied to them. What I want to do is to "separate" these terms shuffling nodes randomly between them so about half of the nodes currently marked "Article" and "Document" will only have "Article" term and the other half will only be marked "Document".
What's the best way to go about this? Is there a module for bulk updating nodes adding/removing taxonomy terms? Am I better off with updating the database directly?
Thank you.
I found a solution for this:
I have "Administrative Views" module installed (Requires: Views, Chaos tools, Views Bulk Operations, Entity API - links are on the module page under dependencies).
From there you select the nodes you want to change and select "change value" in the "operations" dropdown and hit execute. Under "Fields for type {your nodetype}" you can click "tags" for example and enter the new value to overwrite all - or you click "Add new value(s) to Tags, instead of overwriting the existing values." and the value will be added.
It turns out adding a tag this way, there are new tags added for every updated node - so if you edit 20 nodes and add the tag "stackoverflow" there will be 20 tags called "stackoverflow" in the terms list. You may then merge the duplicates with "Term Merge" into one final term.
Since you need to update the taxonomy structure in bulk you can use - Taxonomy Manager
http://drupal.org/project/taxonomy_manager/
Which apart from other features has -
dynamic treeview
mass deleting
mass adding of new terms
moving of terms in hierarchies
You can also take a look at a similar question -
https://drupal.stackexchange.com/questions/11494/adding-taxonomy-terms-to-multiple-nodes-at-once
If nothing helps updating the database sure seems a simpler option, but use it only if you are very sure of your query, and don't forget to take a backup before.. :)
Taxonomy Manager is the a very good module for these purposes I used it myself to tag and add vocabularies to my website that has more than 100 posts. Its interface is also very intuitive and user-friendly.

Deleting instances / fields - Drupal 7

I am having some difficulties with my module I am currently working on. As part of this module I have created a few fields that appear on a form. This form is based in a custom entity.
First I am using field_create_field($field); to create the row in the field_config table. I am then using field_create_instance($instance); to create the row in the instance table and also create the table that begins with field_data_field.
The problem I am running into is how to remove these tables correctly at the end. I have tried manual deletion (via hook_uninstall), I've tried field_delete_field, I've tried to use the remove_instance hook that is built into the Commerce module. Either way, I end up getting lots of field_deleted_data_xxx tables being created. These don't even have data in them as I created a manual query to empty the main data tables before this function was called that seems to create these tables.
Has anyone else ever run into this problem? How do I stop Drupal from creating these tables??
You can't stop Drupal from creating them but I believe you can rid yourself of them totally using field_purge_batch and its related functions.
I really wish I knew the answer to your second question (in your comment above), my instinct would be that if you re-attach the field to the bundle then that data would become automatically available again (otherwise it really doesn't make sense to keep hold of the deleted tables) but I really can't be sure about that.

Refreshing existing nodes to pick up Automatic Nodetitles in Drupal

I have a set of existing nodes for a content type ('foo'). Since then I have installed the Automatic Nodetitles module, which has helped tremendously, since I no longer need to work hard to make standardized names for each node of that type. I have used Automatic Nodetitles in conjunction with Tokens to create an automatic title naming pattern based on Node and CCK fields. This works perfectly for any new node I create of this content types?
How do I refresh existing nodes to pick up their titles with the "Automatic Nodetitles" Drupal 6 module?
Thanks,
Had to do quite a bit of searching to find the solution, but I found it:
http://drupal.org/node/265773#comment-3055470
Specifically:
"Updating nodetitles from existing
nodes
If you set the nodetitle to be auto
generated for some content type,
existing nodes are not affected. You
can update existing nodes by going to
'admin/content/node', then filter for
your content type, mark some nodes and
choose the "Update option" "Update
automatic nodetitles"
Posted to SO for everyone's benefit. One of the "Update options" Is "update automatic nodetitles". I never would have guessed! No need for an additional module or function; it is already there (once Automatic Nodetitles is installed, of course).
You can also use Views Bulk Operations' built-in "List all content" replacement view (defaults to admin/content/node2), which will give you more flexibility in selecting/filtering nodes to update. VBO also allows you to select and perform an action on all nodes, rather than just a page at a time, like Drupal's default content listing.
Than only works well if you have a bunch of nodes, what if you have 5000?

Resources