The imagefield_crop_info variable is just asking for trouble on larger sites.

Use a db table instead.

(Patch momentarily.)

CommentFileSizeAuthor
#1 1566060-use-db-table.patch5.78 KBbdragon

Comments

bdragon’s picture

Status: Active » Needs review
StatusFileSize
new5.78 KB

And here's a patch.

patcon’s picture

Oh good god, +1 on this :)

robloach’s picture

+++ b/imagefield_crop.installundefined
@@ -0,0 +1,103 @@
+  $schema['imagefield_crop_info'] = array(
+    'description' => 'Cropping data for imagefield_crop.',
+    'fields' => array(
+      'fid' => array(
+        'description' => 'Primary key: {file_managed}.fid.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'x' => array(
+        'type' => 'int',

Could probably retrieve the schema by using...

$schema = imagefield_crop_schema();
+++ b/imagefield_crop.installundefined
@@ -0,0 +1,103 @@
+  $query = db_insert('imagefield_crop_info')
+    ->fields(array('fid', 'x', 'y', 'width', 'height'));
+  foreach ($info as $fid => $data) {
+    $data['fid'] = $fid;
+    $query->values($data);
+  }
+  $query->execute();

This executes multiple db_inserts? Wouldn't you need the ->execute() in the foreach?

+++ b/imagefield_crop.moduleundefined
@@ -255,11 +255,11 @@ function _imagefield_add_cropinfo_fields($fid = NULL) {
+  if ($fid) {
+    $crop_info = db_query('SELECT * FROM {imagefield_crop_info} WHERE fid = :fid', array(':fid' => $fid))->fetchAssoc();
+    if (!empty($crop_info)) {

Would be nice to use a db_select() here :-) .

db_select('imagefield_crop_info', 'i')
  ->fields('i')
  ->condition('fid', $fid, '=')
joetsuihk’s picture

Status: Needs review » Closed (duplicate)

#1993144: Use proper database storage for imagefield crop info is a duplicate. This patch was since May 2012 while other is 2013. I will close this and marked on the #1993144 that this is a duplicate and also a patch is available. Hope we can centralize the communications in one thread.