http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=12477
--- Comment #13 from David Cook <dc...@prosentient.com.au> --- Created attachment 29961 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=29961&action=edit DBIC-based framework updater Here is some more complex code that I've devised for updating frameworks. You give it an arrayref of hashrefs, a DBIC resultset, and an arrayref of framework codes. The script will check to see if a row matching the hashref (using the primary key specified in the resultset) exists for each framework. If it exists, it runs an optional "update" callback. If it doesn't exist, it runs an optional "insert" callback (or just inserts it into the database if no callback has been specified). Prior to the database search, the "canon_callback" can be used to modify the hashref for each frameworkcode. In my use case, if I'm loading marc_subfield_structure, I want to change the hidden value to -6 as I'm updating existing frameworks. Of course, if we were loading marc_tag_structure or were installing a framework for the first time, we wouldn't want to do that. I also use the insert/update callbacks to build messages that I sent to the template UI so that the user knows what has been updated. It's not very fast, but DBIC itself says "DBIx::Class is not built for speed, it's built for convenience and ease of use". It certainly is convenient and easy to use :). I have debated the utility of this class a bit. I figure it could be handy when we're installing the sample frameworks, as we could use the "canon_callback" to change the "hidden" value on a per framework and subfield basis. We wouldn't even need the insert/update callbacks. [Note: The DBIx::Class docs do mention that using find_or_create (and thus find_or_new or update_or_create) is subject to a race condition and that it should be run within a transaction. Mind you, lots of what we do in Koha could be subject to a race condition, so I don't know how important it is to get this right at the moment. In any case, there seems to be a few ways of using transactions with DBIC (http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod#TRANSACTIONS). It's not really a big deal when initially installing frameworks, as there shouldn't be anyone to race against, but worth mentioning for updates and in general.] -- You are receiving this mail because: You are watching all bug changes. _______________________________________________ Koha-bugs mailing list Koha-bugs@lists.koha-community.org http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/