Posted by mossy2100 on March 19, 2012 at 10:32pm
Hi guys
This is a new D7 module for finding and replacing text in the database. I find that I often want to be able to do this.
http://astromultimedia.com/db_find_replace.zip
I thought I would share it with you for beta testing before I contrib it. If you could have a play and tell me your suggestions, that would be great!
Mossy

Comments
star library
Sorry - the module depends on the star library (also created by me). It's just useful PHP and JS functions.
Download from: http://astromultimedia.com/star.zip
Unzip into sites/all/libraries.
Cheers,
Mossy
Sounds interesting
Hey Mossy, could you explain a little more what your module does?
I used to use http://drupal.org/project/scanner and found it quite useful when I needed it, but it's never been brought up to D7. Does your module do something similar?
Jeff
it's similar
It searches every text field in the database. Sometimes I need this if I want to find every reference to an image or a content type, for example. It doesn't support regular expressions yet, although I would like to add that later.
HTH
Mossy
feedback
I did a quick code review. Looks pretty clean. It's a pretty nice utility that I would use, so the following advice reflects the fact that you've asked for feedback before putting it in contrib. You really should just put it up on d.o if you are serious about it, git sandboxes are awesome.
I have two main qualms.
You shouldn't use $_SESSION to pass values around, look at setting $form_state['rebuild'] and storing data on the $form_state (eg. $form_state['mymodule'][...]
The requirement of star library will put people off. Remember, people complain about having to have ctools so they will question the dependency on this library. Also a lot of your star library functions are simply re-implementations of PHP code for no good reason other the name and function prototype makes sense to you. The downside is unnecessary abstraction that turns some people off. I recommend moving any dependencies into your module and removing the star library dependency. If you are not sure what I'm referring to, see this sample in strings.php (I removed comments FYI), it's just OTT.
<?php
function post2html($str) {
return htmlspecialchars(stripslashes($str), ENT_QUOTES);
}
function db2html($str) {
return htmlspecialchars($str, ENT_QUOTES);
}
function left($str, $n) {
return substr($str, 0, $n);
}
function right($str, $n) {
return substr($str, -$n);
}
?>
HTH
thanks
Thanks, Sime
I wouldn't require all of star library for the module - that's my own library that I've developed over years, and is just convenient for me to use. I haven't scanned/polished all the functions in there for a long time. Before contributing I will probably just factor out the functions I need.
I will take on what you said about $_SESSION, though. I like using session variables, it means you can go back to the form at any time and it will display the last values entered, whereas using $form_state won't survive beyond the submit handler (afaik). But I will look into it.
Thanks for the feedback! Please install the module and have a play, to see if it works the way you like.
Mossy
Yes you are not using many
Yes you are not using many star library functions, so it would make sense to move them into the module.
You're right about the form_state not persisting. Best practice is to use ctools caching functions for $form_state['values'] storage, some of the benefits being that you're not polluting the $_SESSION array and teaching other developers bad practice.
cool
Cheers, thanks for that! I will check it out.
Very much appreciate the feedback :)