Maintenance task to get rid of .jpg in picture title

pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Sat, 2005-04-30 11:13

I usually dont rename the title of photos in my Gallery. This results in items with for instance titles such as IMG_0000.jpg and often with the same description (especially if you upload with Gallery Remote). With G1 these titles became 'IMG 0000' which to me looks nicer.

Therefor, I've made a System Maintenance script which removes the filename extension and replaces underscores with spaces in the title for photo and movie items. Also, it deletes the description/summary if they only contain the filename.

I find this very useful for pictures I added with Gallery Remote or pictures migrated from G1. Download the file below and place it in gallery2/modules/core/classes. For it to be recogniced you need run this SQL statement (might need to flush the database cashe - I'm not sure)
INSERT INTO g2_factorymap VALUES ('MaintenanceTask', 'SanitizeItemCaptionsTask', 'SanitizeItemCaptionsTask', 'modules/core/classes/SanitizeItemCaptionsTask.class', 'core', 'N;', '4');

AttachmentSize
SanitizeItemCaptionsTask.class.gz1.65 KB
 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sat, 2005-04-30 14:52

pelle, nice.. how about putting this in its own module and register the task automatically when the module activates?

 
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Sat, 2005-04-30 16:57

Sure I could, is this something of interest for cvs?

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Sat, 2005-04-30 21:14

We might want to make a catch-all module for things like this. Like a "Maintenance" module that has a selection of 10 or 15 common tasks that people might want to do. Most folks probably don't need it, but it saves us from having to write a new module every time we want a new maintenance task. That would probably be a fine thing to have in CVS.

On another note, perhaps we should strip the .jpg tag (and other known file tags) off of the title when we upload new files? If we strip that off and convert underscores/dashes to spaces, then most file names will look semi-decent by default.

 
Gaile

Joined: 2002-07-20
Posts: 1301
Posted: Sat, 2005-04-30 21:24
bharat wrote:
On another note, perhaps we should strip the .jpg tag (and other known file tags) off of the title when we upload new files? If we strip that off and convert underscores/dashes to spaces, then most file names will look semi-decent by default.

Sounds like a plan to me.

Actually, the more I think about it, the more I like the idea. It would look cleaner, and I'm for anything that makes layouts look less cluttered.

Gaile

 
buut
buut's picture

Joined: 2003-06-18
Posts: 196
Posted: Sat, 2005-04-30 22:04

When conducted in a Module you could also rename the Dsc or mvc to something useful like 'Holiday in Europe'. As an Album option/action.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Sun, 2005-05-01 00:15

I added a G2 task for this.

 
g0d

Joined: 2005-03-12
Posts: 22
Posted: Sun, 2005-05-01 05:29

maybe you can add a ability to rename all the items in an albul to say "Album Name 001", "Album Name 002" ...

this can be really helpful.

Thanks

 
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Sun, 2005-05-01 20:29

g0d, that sounds like something you would wanna do to a single album, not the whole gallery.

Anyways, here's the module for SanitizeItemCaptions. Other Maintenance tasks can easily be added to the tasks dir, just bump the version number. Perfect if you want to craft your own tasks.

 
g0d

Joined: 2005-03-12
Posts: 22
Posted: Mon, 2005-05-02 02:29

i agree, this will be done per album basis ... but for the whole album.

I add a lot of images found from the web to my gallery, and over tim the filenames become a lot wierd. Thats the reason for this.

Can your module do such a thing ?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-05-02 02:36

g0d, it won't do exactly what you want, but you may be able to modify it to do what you want.

 
g0d

Joined: 2005-03-12
Posts: 22
Posted: Mon, 2005-05-02 17:10

i will try that ... and will upload the module if i achieve some success.

 
d3vlabs

Joined: 2005-05-10
Posts: 100
Posted: Tue, 2005-05-10 20:37

SQL statement produces the following error:

INSERT INTO g2_factorymap VALUES ('MaintenanceTask', 'SanitizeItemCaptionsTask', 'SanitizeItemCaptionsTask', 'modules/core/classes/SanitizeItemCaptionsTask.class', 'core', 'N;', '4');"

MySQL said:

#1146 - Table 'd3v_gala.g2_factorymap' doesn't exist

Even thou the table is physically there. I can see it in PHPmyadmin. Any ideas? Should I drop the tables and try to do re-do them again. Or is there any way to do this without the seperate SQL query.
I installed the filed u provided in 3 different folders just to make sure :x, so that's not it. Thanks for your time.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2005-05-10 21:28

use the later attachment that is a module.. then you don't need any sql.

 
d3vlabs

Joined: 2005-05-10
Posts: 100
Posted: Tue, 2005-05-10 22:39

muhaha it worked. gg froggy :x thanks mindless

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Wed, 2005-05-11 03:10

Nice work. I like it.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Mon, 2005-05-30 04:44

FYI, this module doesn't work with some of the latest API changes. I don't know if the only thing that needs to be changed is this

        $this->setRequiredCoreApi(array(5, 0));
        $this->setRequiredModuleApi(array(0, 9));

to this

        $this->setRequiredCoreApi(array(6, 0));
        $this->setRequiredModuleApi(array(0, 12));

But when I made those changes I was able to reactivate the module and sanitize titles. So it worked. I just don't know if anything else needs to be updated.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-05-30 06:10

API version changes are described in a sticky topic in this forum, so you can see if this module does anything that needs updating to conform to current apis.

 
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Mon, 2005-05-30 13:43

Thats all you need to do, update the required API's and you're fine.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Mon, 2005-05-30 14:57

Thanks guys. I did look through the code and the sticky and thought that was the case. But not being familar with the G2 code I wasn't sure. I am learning more each time I get in there and mess around with something.

 
Florie

Joined: 2005-05-22
Posts: 11
Posted: Mon, 2005-07-25 10:17

looks like it doesnt work @ my beta4

Gallery-Version = 2.0-beta-4 Kern 0.9.32
PHP-Version = 4.3.8 apache2handler
Webserver = Apache/2.0.50
Datenbank = mysql 4.0.21-Max
Werkzeuge = Gd, ImageMagick, NetPBM, Thumbnail, Exif
Betriebssystem = Linux server2 2.6.8-24.16-smp #1 SMP Thu Jun 2 12:09:57 UTC 2005 i686
Browser = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)

i receive this message:

Warning: Missing argument 1 for run() in /srv/www/htdocs/web25/html/gallery2/modules/maintenance/tasks/SanitizeItemCaptionsTask.class on line 56

Fatal error: Call to a member function on a non-object in /srv/www/htdocs/web25/html/gallery2/modules/maintenance/tasks/SanitizeItemCaptionsTask.class on line 65