Hi, I have a big problem. I have a ejournal in my website and I have about 1000 articles. Unfortunately, some of these are token from a website that has changed its policy and don't allow us to publish its material: only the 25% of articles can be published. We can distinguish these articles because there is always the original link that obviously starts with the same strings. We must select all the articles containing these strings in their body, and tells drupal to take the first 4 5 lines and delete the rest of contents. I have 2 ideas, but I' not able to make it: 1. with a sql query, I think all contents are in the node_revisions table. 2. publishing only the teaser of the article. I think the second method is easier, but have you got some ideas how publish only a teaser and hide the entire body of some nodes?
thanks for your attention and patience. Bye.
Simone,
My opinion (which is not authoritative) regarding the easiest strategy to solve your problem would be to write a query which would select the contents of the teaser field and put it into a variable (remember to include the write the "WHERE" clause in the query to only pull the nodes you want to affect). Then you write another query which replaces the current content of the body field with the content of the teaser field that is in the variable that you stored.
The snippet you write can be run using Devel module's "drupal execute" tool. That way you would avoid having to write a module to implement a one-time task.
f you are not experienced writing code like this I'll give you this unsolicited advice to help get you started...
The first thing you need to do is to write your SELECT query and make sure it works and pulls in only the right rows from the node revisions table. The good part about this part is that you don't need to mess with PHP at this stage. You just query the database directly, using a tool like phpMyAdmin or the command line, whatever. When doing SELECT queries your blood preassure stays low because SELECT queries don't change the DB. [But still, back up the db before you even start, because you might forget after you start working.]
Next you write the query for replacing the body field with the teaser field contents. Again, no PHP, you just copy teaser contents from one node and hard code that into your query. (Be careful to add a clause "WHERE nid=25" --- where "25" is the node id where you copied the teaser from. This part raises your blood pressure a bit, since the test query actually does change the database. But by cleary limiting the query to one row, you keep things under good control.)
Once you have tested that the second query works, you can build the PHP snippet to cycle through each record creating new body fields using the variable which will have stored the results of the first query.
By having tested that your queries are correct first, you'll have much greater confidence building and then debugging the PHP snippet.
As an alternative to this whole approach to your problem, you might be able to write complicated custom views which would sometimes display the teaser field and sometimes display the full node based on taxonomy, url strings, or whatever. But I think it is cleaner to simply change the body field by putting in the data there that you actually want.
Good luck, report back,
Shai
On Wed, Dec 10, 2008 at 5:10 AM, Simone Dal Maso simone.dalmaso@juvox.itwrote:
Hi, I have a big problem. I have a ejournal in my website and I have about 1000 articles. Unfortunately, some of these are token from a website that has changed its policy and don't allow us to publish its material: only the 25% of articles can be published. We can distinguish these articles because there is always the original link that obviously starts with the same strings. We must select all the articles containing these strings in their body, and tells drupal to take the first 4 5 lines and delete the rest of contents. I have 2 ideas, but I' not able to make it:
- with a sql query, I think all contents are in the node_revisions table.
- publishing only the teaser of the article.
I think the second method is easier, but have you got some ideas how publish only a teaser and hide the entire body of some nodes?
thanks for your attention and patience. Bye.
-- [ Drupal support list | http://lists.drupal.org/ ]
Shai, really, thank you very much. Your message was detailed and I forward it to a friend of mine and with 2 query we solved the problem. Still thanks. bye.
----- Original Message ----- From: "Shai Gluskin" shai@content2zero.com To: support@drupal.org Sent: Wednesday, December 10, 2008 5:14 PM Subject: Re: [support] sql query and other
Simone,
My opinion (which is not authoritative) regarding the easiest strategy to solve your problem would be to write a query which would select the contents of the teaser field and put it into a variable (remember to include the write the "WHERE" clause in the query to only pull the nodes you want to affect). Then you write another query which replaces the current content of the body field with the content of the teaser field that is in the variable that you stored.
The snippet you write can be run using Devel module's "drupal execute" tool. That way you would avoid having to write a module to implement a one-time task.
f you are not experienced writing code like this I'll give you this unsolicited advice to help get you started...
The first thing you need to do is to write your SELECT query and make sure it works and pulls in only the right rows from the node revisions table. The good part about this part is that you don't need to mess with PHP at this stage. You just query the database directly, using a tool like phpMyAdmin or the command line, whatever. When doing SELECT queries your blood preassure stays low because SELECT queries don't change the DB. [But still, back up the db before you even start, because you might forget after you start working.]
Next you write the query for replacing the body field with the teaser field contents. Again, no PHP, you just copy teaser contents from one node and hard code that into your query. (Be careful to add a clause "WHERE nid=25" --- where "25" is the node id where you copied the teaser from. This part raises your blood pressure a bit, since the test query actually does change the database. But by cleary limiting the query to one row, you keep things under good control.)
Once you have tested that the second query works, you can build the PHP snippet to cycle through each record creating new body fields using the variable which will have stored the results of the first query.
By having tested that your queries are correct first, you'll have much greater confidence building and then debugging the PHP snippet.
As an alternative to this whole approach to your problem, you might be able to write complicated custom views which would sometimes display the teaser field and sometimes display the full node based on taxonomy, url strings, or whatever. But I think it is cleaner to simply change the body field by putting in the data there that you actually want.
Good luck, report back,
Shai
On Wed, Dec 10, 2008 at 5:10 AM, Simone Dal Maso simone.dalmaso@juvox.itwrote:
Hi, I have a big problem. I have a ejournal in my website and I have about 1000 articles. Unfortunately, some of these are token from a website that has changed its policy and don't allow us to publish its material: only the 25% of articles can be published. We can distinguish these articles because there is always the original link that obviously starts with the same strings. We must select all the articles containing these strings in their body, and tells drupal to take the first 4 5 lines and delete the rest of contents. I have 2 ideas, but I' not able to make it:
- with a sql query, I think all contents are in the node_revisions
table. 2. publishing only the teaser of the article. I think the second method is easier, but have you got some ideas how publish only a teaser and hide the entire body of some nodes?
thanks for your attention and patience. Bye.
-- [ Drupal support list | http://lists.drupal.org/ ]
--------------------------------------------------------------------------------
-- [ Drupal support list | http://lists.drupal.org/ ]
Simone --,
You are welcome!
Could you share the snippet that was written and any changes from the path that I laid out, -- then maybe I'd create a docs page on this and a wider circle of people could benefit.
I'm particularly curious, reading between the lines of your note, whether your collaborator was able to make the changes with SQL only and bypassing the PHP part. My SQL is week so I'd definitely be interested in knowing whether he was able to do it all directly on the db without storing the contents of all the teasers in a PHP array variable.
Thanks,
Shai On 12/12/08, Simone Dal Maso simone.dalmaso@juvox.it wrote:
Shai, really, thank you very much. Your message was detailed and I forward it to a friend of mine and with 2 query we solved the problem. Still thanks. bye.
----- Original Message ----- From: "Shai Gluskin" shai@content2zero.com To: support@drupal.org Sent: Wednesday, December 10, 2008 5:14 PM Subject: Re: [support] sql query and other
Simone,
My opinion (which is not authoritative) regarding the easiest strategy to solve your problem would be to write a query which would select the contents of the teaser field and put it into a variable (remember to include the write the "WHERE" clause in the query to only pull the nodes you want to affect). Then you write another query which replaces the current content of the body field with the content of the teaser field that is in the variable that you stored.
The snippet you write can be run using Devel module's "drupal execute" tool. That way you would avoid having to write a module to implement a one-time task.
f you are not experienced writing code like this I'll give you this unsolicited advice to help get you started...
The first thing you need to do is to write your SELECT query and make sure it works and pulls in only the right rows from the node revisions table. The good part about this part is that you don't need to mess with PHP at this stage. You just query the database directly, using a tool like phpMyAdmin or the command line, whatever. When doing SELECT queries your blood preassure stays low because SELECT queries don't change the DB. [But still, back up the db before you even start, because you might forget after you start working.]
Next you write the query for replacing the body field with the teaser field contents. Again, no PHP, you just copy teaser contents from one node and hard code that into your query. (Be careful to add a clause "WHERE nid=25" --- where "25" is the node id where you copied the teaser from. This part raises your blood pressure a bit, since the test query actually does change the database. But by cleary limiting the query to one row, you keep things under good control.)
Once you have tested that the second query works, you can build the PHP snippet to cycle through each record creating new body fields using the variable which will have stored the results of the first query.
By having tested that your queries are correct first, you'll have much greater confidence building and then debugging the PHP snippet.
As an alternative to this whole approach to your problem, you might be able to write complicated custom views which would sometimes display the teaser field and sometimes display the full node based on taxonomy, url strings, or whatever. But I think it is cleaner to simply change the body field by putting in the data there that you actually want.
Good luck, report back,
Shai
On Wed, Dec 10, 2008 at 5:10 AM, Simone Dal Maso simone.dalmaso@juvox.itwrote:
Hi, I have a big problem. I have a ejournal in my website and I have about 1000 articles. Unfortunately, some of these are token from a website that has changed its policy and don't allow us to publish its material: only the 25% of articles can be published. We can distinguish these articles because there is always the original link that obviously starts with the same strings. We must select all the articles containing these strings in their body, and tells drupal to take the first 4 5 lines and delete the rest of contents. I have 2 ideas, but I' not able to make it:
- with a sql query, I think all contents are in the node_revisions
table. 2. publishing only the teaser of the article. I think the second method is easier, but have you got some ideas how publish only a teaser and hide the entire body of some nodes?
thanks for your attention and patience. Bye.
-- [ Drupal support list | http://lists.drupal.org/ ]
-- [ Drupal support list | http://lists.drupal.org/ ]
-- [ Drupal support list | http://lists.drupal.org/ ]