1

I have a content type which I enter data to by means of a csv file. Everything works fine as I have multiple content-types set up like this.

However, I'm trying to clean-up the database and remove data that is from 2012 and before.

Within Drupal at the /admin/content/filter url, I set the parameters for the content-type and such as:

node type is Print Data
and is created before 2013-01-01
and node status is published

(note, I just used the code indicator to set-off the options for this post)

Upon return, I have pages of content with each page showing 500+ results. I can delete them from within Drupal, but only at 500 at a time so I went to phpMyadmin but in there, I can only see/find data that is from 2013.

So where is Drupal storing all that other data if not in the database?

3

First of all allow me to say that you should not delete from db directly unless you are really aware of drupal's architecture and how the db tables are organized. (basically have in mind drupal store information for an entity in multiple tables not only one.)

Secondly have in mind in case you are looking through node table for a node created prior 2013-01-01 m the actual date is saved as unix timestamp (1357020000)

Thirdly allow me to recommend you VBO (View Bulk Operation) module for the exact scenario you are looking for , it will let you bulk delete, unpublish, publish (even has an API for custom bulk operations). I would create a simple view accesible for admins only, exposed filters for node creation date and some basic bulk operation. Please consider using this

1
  • yes, on our live sites I use VBO but on this particular site that's not installed and there are issues with adding modules to this particular install due to shared server issues. However, I will try using a view to see if I can restrict somehow there and get around this 500 limit. Thanks. – kelly johnson Oct 14 '13 at 21:51
1

As you cannot go with VBO(View bulk operation), I would suggest you to create a custom script for deleting the code rather than deleting manually from the database:

  • Can take the reference from devel_generate_content_kill(), this function is called by the devel generate module to delete the multiple nodes.
  • As the function provides a way to create the script, you need to modify only field condition as per you need.
  • It would be wise to keep the backup of the existing database(so in case anything goes wrong you can rollback easily).

    function custom_node_delete_op() {
    // Define the time value , Example of 10 mins.
    $time_since = time() - 600;

    // This will provide the node ids of nodes older than 10 min. $results = db_select('node', 'n')
    ->fields('n', array('nid'))
    ->condition('type', 'CONTENT_TYPE', 'IN')
    ->condition('created', $time_since, '<')
    ->execute();
    foreach ($results as $result) {
    $nids[] = $result->nid;
    }

    // Execute the code to delete the nodes.
    if (!empty($nids)) {
    node_delete_multiple($nids);
    drupal_set_message(t('Deleted %count nodes.', array('%count' => count($nids))));
    }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.