[wellwell-devel] [SCM] Interchange wellwell catalog branch, master, updated. a9275002556bd84cfe5f3536f242279b400aa7cc

Stefan Hornburg racke at rt.icdevgroup.org
Tue Jun 23 18:38:55 UTC 2009


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Interchange wellwell catalog".

The branch, master has been updated
       via  a9275002556bd84cfe5f3536f242279b400aa7cc (commit)
       via  69fc3c6cf33d1213c3bd648a4d14db3c69e3d2b8 (commit)
      from  8bb6e91ac695019bf7e689cbacd0bf6c4bb220f2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a9275002556bd84cfe5f3536f242279b400aa7cc
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Tue Jun 23 20:38:42 2009 +0200

    using [image-display]

commit 69fc3c6cf33d1213c3bd648a4d14db3c69e3d2b8
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Tue Jun 23 20:37:49 2009 +0200

    changed database structure for images, added new tags to deal with images

-----------------------------------------------------------------------

Summary of changes and diff:
 code/image_display.tag            |   35 ++++++++++++
 code/image_update.tag             |  107 +++++++++++++++++++++++++++++++++++++
 components/product_info           |   13 +----
 components/product_list           |   19 ++-----
 database/mysql/images.sql         |    8 ++-
 database/mysql/product_images.sql |    8 ++-
 database/pgsql/images.sql         |    8 ++-
 database/pgsql/product_images.sql |    8 ++-
 8 files changed, 172 insertions(+), 34 deletions(-)
 create mode 100644 code/image_display.tag
 create mode 100644 code/image_update.tag

diff --git a/code/image_display.tag b/code/image_display.tag
new file mode 100644
index 0000000..1c399e4
--- /dev/null
+++ b/code/image_display.tag
@@ -0,0 +1,35 @@
+UserTag image_display Order sku group
+UserTag image_display HasEndTag
+UserTag image_display Routine <<EOR
+sub {
+	my ($sku, $group, $body) = @_;
+	my ($sku_qtd, $group_qtd, $set, $img, $loc, $hash);
+
+	$Tag->perl({tables => 'images product_images'});
+
+	$sku_qtd = $Db{product_images}->quote($sku);
+	$group_qtd = $Db{product_images}->quote($group);
+
+	$set = $Db{product_images}->query({sql => qq{select location,width,height from images I, product_images PI where PI.sku = $sku_qtd and PI.image_group = $group_qtd and PI.image = I.code}, hashref => 1});
+
+	if (@$set) {
+		if (@$set > 1) {
+			Log("More than one image found for sku $sku and group $group.");
+		}
+		
+		$hash = $set->[0];
+	} else {
+#		Log("No image found for sku $sku and group $group.");
+	}
+
+	if ($body) {
+		return $Tag->uc_attr_list({hash => $hash, body => $body});
+	} 
+	elsif ($hash) {
+		return $hash->{location};
+	}
+
+	# dummy image
+	return "nopic-$group.jpg";
+}
+EOR
diff --git a/code/image_update.tag b/code/image_update.tag
new file mode 100644
index 0000000..b80f72f
--- /dev/null
+++ b/code/image_update.tag
@@ -0,0 +1,107 @@
+UserTag image_update Order filename label code
+UserTag image_update AddAttr
+UserTag image_update Routine <<EOR
+sub {
+	my ($filename, $label, $code) = @_;
+	my ($inforef, $imgfilename, $origfilename, $imgname, $imgdir, $imgcode, 
+		$sizes, $destination, $ret, $filetime, $set, $exists);
+
+	$imgdir = $Variable->{IMAGE_DIR} || 'images';
+
+	# ensure that file exists
+	unless (-f $filename) {
+		Log("Missing image file %s", $filename);
+		return;
+	}
+
+	# determine age of image
+	$filetime = $Tag->file_info({name => $filename, time => 1});
+
+	$Tag->perl({tables => 'images image_sizes product_images'});
+	
+	# image already present ?
+	$set = $Db{images}->query(q{select code,original_time,name from images where original_file = '%s'}, $filename);
+	if (@$set) {
+		if ($set->[0]->[1] == $filetime) {
+			# no changes
+			return;
+		}
+		$imgcode = $set->[0]->[0];
+		$origfilename = $set->[0]->[2];
+		$exists = 1;
+	}
+
+	# get dimensions for original file
+	unless ($inforef = $Tag->image_info({name => $filename, hash => 1})) {
+		Log("Error getting info on %s.");
+		return;
+	}
+
+	# determine file name for the image
+	$imgname = $Tag->clean_url($label, $code);
+	$imgfilename = "$imgdir/$imgname.$inforef->{type}";
+
+	# copy file to new location
+	unless ($Tag->cp({from => $filename, 
+				  to => $imgfilename,
+				  umask => 22})) {
+		Log("Error copying %s to %s", $filename, $imgfilename);
+		return;
+	}
+
+	if ($imgcode && $origfilename ne $imgfilename) {
+		$ret = $Tag->unlink($origfilename);
+		Log("Deleted file $origfilename: $ret.");	
+	}
+
+	# record for original image
+	my %image = (name => $imgfilename,
+		 created => $filetime,
+		 width => $inforef->{width},
+		 original_file => $filename,
+	 	 original_time => $filetime,
+	 	 height => $inforef->{height},
+	 	 format => $inforef->{type});
+
+	if ($imgcode) {
+	}  else {	
+	
+
+		$imgcode = $Db{images}->set_slice([{dml => 'insert'}], \%image);
+
+		unless ($imgcode) {
+			Log("Failed to create database record for %s", $filename);
+			return;
+		}
+	}
+
+	# determine sizes
+	$sizes = $Db{image_sizes}->query({sql => q{select * from image_sizes},
+		hashref => 1});
+
+	# resize image
+	for my $size (@$sizes) {
+		$destination = "$imgdir/$size->{name}/$imgname.$inforef->{type}";
+
+		$ret = $Tag->image_resize({
+			name => $imgfilename,
+			outfile => $destination,
+			width => $size->{width},
+			height => $size->{height}
+		});
+
+		unless ($ret) {
+			Log ("Error on resizing image to %s", $destination);
+			return;
+		}
+
+		# store in database
+		$ret = $Db{product_images}->set_slice('', sku => $code,
+									   image => $imgcode,
+									   image_group => $size->{name},
+									   location => $destination);
+	}
+
+	return 1;
+}
+EOR
diff --git a/components/product_info b/components/product_info
index 60be0ac..12f8191 100644
--- a/components/product_info
+++ b/components/product_info
@@ -3,18 +3,7 @@
 <h2>[item-field manufacturer] [item-field name]</h2>
 
 <div class="image">
-	[image-list
-		join_table=product_images
-		key_field=sku
-		key="[item-field sku]"
-		size=original
-		where="ji.main IS true"
-	]
-	[list]
-		[image-list-param img-src]
-	[/list]
-	[no-match]<img src="__IMAGE_URL__/style/no_product_image.png" alt="No image for this product">[/no-match]
-	[/image-list]
+	<img src="[image-display [item-code] detail]">
 </div>
 
 <ul>
diff --git a/components/product_list b/components/product_list
index 9efbd36..4489ade 100644
--- a/components/product_list
+++ b/components/product_list
@@ -3,24 +3,17 @@
 <h2>[sql-param name]</h2>
 [/list]
 [/query]
-
 [product-list category="__CATEGORY__" ml=10 more=1 form="category=__CATEGORY__"]
+[no-match]
+<div class="oneThirdGrad">
+Nothing found.
+</div>
+[/no-match]
 [list]
 
 <div class="oneThirdGrad">
 
-<p class="image">
-[image-list 
-	where='i.inactive IS NOT TRUE AND ji.main IS TRUE' 
-	join_table='product_images' 
-	key_field='sku'
-	key='[product-field sku]'
-	size='small'
-
-]
-	[image-list-param img-src]
-[/image-list]
-</p>
+<p class="image"><img src="[image-display [product-code] list]"></p>
 
 <h3><a href="[product-code]">[product-field manufacturer] [product-field name]</a></h3>
 <p class="description">
diff --git a/database/mysql/images.sql b/database/mysql/images.sql
index 96ca660..8a66343 100644
--- a/database/mysql/images.sql
+++ b/database/mysql/images.sql
@@ -3,8 +3,12 @@ CREATE TABLE images
   code int unsigned NOT NULL auto_increment,
   name varchar(255),
   format char(3),
-  created datetime,
-  author int unsigned,
+  original_file varchar(255) NOT NULL DEFAULT '',
+  original_time integer unsigned not null default 0,
+  created integer,
+  author int unsigned NOT NULL DEFAULT 0,
+  width integer unsigned NOT NULL DEFAULT 0,
+  height integer unsigned NOT NULL DEFAULT 0,
   inactive boolean DEFAULT FALSE,
   PRIMARY KEY (code)
 )
diff --git a/database/mysql/product_images.sql b/database/mysql/product_images.sql
index 5a09be3..c59a022 100644
--- a/database/mysql/product_images.sql
+++ b/database/mysql/product_images.sql
@@ -1,8 +1,10 @@
 CREATE TABLE product_images
 (
+  code int unsigned NOT NULL auto_increment,
   sku varchar(64) NOT NULL,
   image int unsigned NOT NULL,
-  main boolean DEFAULT false,
-  PRIMARY KEY (sku, image)
+  image_group varchar(64) NOT NULL default '',
+  location varchar(255) NOT NULL default '',
+  PRIMARY KEY (code),
+  KEY (sku, image_group)
 );
-
diff --git a/database/pgsql/images.sql b/database/pgsql/images.sql
index 42e54e9..9f1ea5b 100644
--- a/database/pgsql/images.sql
+++ b/database/pgsql/images.sql
@@ -3,8 +3,12 @@ CREATE TABLE images
   code serial NOT NULL,
   name varchar(255),
   format char(3),
-  created timestamp,
-  author int4,
+  original_file varchar(255) NOT NULL DEFAULT '',
+  original_time integer not null default 0,
+  created integer,
+  author integer NOT NULL DEFAULT 0,
+  width integer NOT NULL DEFAULT 0,
+  height integer NOT NULL DEFAULT 0,
   inactive bool DEFAULT false,
   CONSTRAINT images_pkey PRIMARY KEY (code)
 );
diff --git a/database/pgsql/product_images.sql b/database/pgsql/product_images.sql
index 0593828..f96b4bc 100644
--- a/database/pgsql/product_images.sql
+++ b/database/pgsql/product_images.sql
@@ -1,7 +1,11 @@
 CREATE TABLE product_images
 (
+  code serial,
   sku varchar(64) NOT NULL,
   image int4 NOT NULL,
-  main bool DEFAULT FALSE,
-  CONSTRAINT product_images_pkey PRIMARY KEY (sku, image)
+  image_group varchar(64) NOT NULL default '',
+  location varchar(255) NOT NULL default '',
+  CONSTRAINT product_images_pkey PRIMARY KEY (code)
 );
+CREATE INDEX product_images_sku_group ON product_images (sku, image_group);
+


hooks/post-receive
-- 
Interchange wellwell catalog



More information about the wellwell-devel mailing list