partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 53badb86f5a9b4e9b622fdaa7372a324027c57a4
parent 6a7d6127cf61248002881fe67534a96dcc0bbfc0
Author: Felicitus <felicitus@felicitus.org>
Date:   Thu, 16 Jun 2011 09:29:34 +0200

merged

Diffstat:
Afrontend/file.php | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Mfrontend/image.php | 6+++---
Afrontend/js/Components/Part/PartAttachmentGrid.js | 153+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mfrontend/js/Components/Part/PartEditor.js | 15++++++++++++++-
Mfrontend/js/Components/Part/PartEditorWindow.js | 3++-
Afrontend/js/Models/PartAttachment.js | 15+++++++++++++++
Afrontend/resources/mimetypes/7z.png | 0
Afrontend/resources/mimetypes/README | 27+++++++++++++++++++++++++++
Afrontend/resources/mimetypes/ai.png | 0
Afrontend/resources/mimetypes/aiff.png | 0
Afrontend/resources/mimetypes/asc.png | 0
Afrontend/resources/mimetypes/audio.png | 0
Afrontend/resources/mimetypes/bin.png | 0
Afrontend/resources/mimetypes/bz2.png | 0
Afrontend/resources/mimetypes/c.png | 0
Afrontend/resources/mimetypes/cfc.png | 0
Afrontend/resources/mimetypes/cfm.png | 0
Afrontend/resources/mimetypes/chm.png | 0
Afrontend/resources/mimetypes/class.png | 0
Afrontend/resources/mimetypes/conf.png | 0
Afrontend/resources/mimetypes/cpp.png | 0
Afrontend/resources/mimetypes/cs.png | 0
Afrontend/resources/mimetypes/css.png | 0
Afrontend/resources/mimetypes/csv.png | 0
Afrontend/resources/mimetypes/deb.png | 0
Afrontend/resources/mimetypes/divx.png | 0
Afrontend/resources/mimetypes/doc.png | 0
Afrontend/resources/mimetypes/dot.png | 0
Afrontend/resources/mimetypes/eml.png | 0
Afrontend/resources/mimetypes/enc.png | 0
Afrontend/resources/mimetypes/file.png | 0
Afrontend/resources/mimetypes/gif.png | 0
Afrontend/resources/mimetypes/gz.png | 0
Afrontend/resources/mimetypes/hlp.png | 0
Afrontend/resources/mimetypes/htm.png | 0
Afrontend/resources/mimetypes/html.png | 0
Afrontend/resources/mimetypes/image.png | 0
Afrontend/resources/mimetypes/iso.png | 0
Afrontend/resources/mimetypes/jar.png | 0
Afrontend/resources/mimetypes/java.png | 0
Afrontend/resources/mimetypes/jpeg.png | 0
Afrontend/resources/mimetypes/jpg.png | 0
Afrontend/resources/mimetypes/js.png | 0
Afrontend/resources/mimetypes/lua.png | 0
Afrontend/resources/mimetypes/m.png | 0
Afrontend/resources/mimetypes/mm.png | 0
Afrontend/resources/mimetypes/mov.png | 0
Afrontend/resources/mimetypes/mp3.png | 0
Afrontend/resources/mimetypes/mpg.png | 0
Afrontend/resources/mimetypes/odc.png | 0
Afrontend/resources/mimetypes/odf.png | 0
Afrontend/resources/mimetypes/odg.png | 0
Afrontend/resources/mimetypes/odi.png | 0
Afrontend/resources/mimetypes/odp.png | 0
Afrontend/resources/mimetypes/ods.png | 0
Afrontend/resources/mimetypes/odt.png | 0
Afrontend/resources/mimetypes/ogg.png | 0
Afrontend/resources/mimetypes/pdf.png | 0
Afrontend/resources/mimetypes/pgp.png | 0
Afrontend/resources/mimetypes/php.png | 0
Afrontend/resources/mimetypes/pl.png | 0
Afrontend/resources/mimetypes/png.png | 0
Afrontend/resources/mimetypes/ppt.png | 0
Afrontend/resources/mimetypes/ps.png | 0
Afrontend/resources/mimetypes/py.png | 0
Afrontend/resources/mimetypes/ram.png | 0
Afrontend/resources/mimetypes/rar.png | 0
Afrontend/resources/mimetypes/rb.png | 0
Afrontend/resources/mimetypes/rm.png | 0
Afrontend/resources/mimetypes/rpm.png | 0
Afrontend/resources/mimetypes/rtf.png | 0
Afrontend/resources/mimetypes/sig.png | 0
Afrontend/resources/mimetypes/sql.png | 0
Afrontend/resources/mimetypes/swf.png | 0
Afrontend/resources/mimetypes/sxc.png | 0
Afrontend/resources/mimetypes/sxd.png | 0
Afrontend/resources/mimetypes/sxi.png | 0
Afrontend/resources/mimetypes/sxw.png | 0
Afrontend/resources/mimetypes/tar.png | 0
Afrontend/resources/mimetypes/tex.png | 0
Afrontend/resources/mimetypes/tgz.png | 0
Afrontend/resources/mimetypes/txt.png | 0
Afrontend/resources/mimetypes/vcf.png | 0
Afrontend/resources/mimetypes/video.png | 0
Afrontend/resources/mimetypes/vsd.png | 0
Afrontend/resources/mimetypes/wav.png | 0
Afrontend/resources/mimetypes/wma.png | 0
Afrontend/resources/mimetypes/wmv.png | 0
Afrontend/resources/mimetypes/xls.png | 0
Afrontend/resources/mimetypes/xml.png | 0
Afrontend/resources/mimetypes/xpi.png | 0
Afrontend/resources/mimetypes/xvid.png | 0
Afrontend/resources/mimetypes/zip.png | 0
Mfrontend/upload.php | 2++
Msrc/de/RaumZeitLabor/PartKeepr/Footprint/FootprintManager.php | 28+++++++++++++---------------
Msrc/de/RaumZeitLabor/PartKeepr/Image/Image.php | 5+++--
Msrc/de/RaumZeitLabor/PartKeepr/ManufacturerICLogo/ManufacturerICLogoService.php | 3++-
Msrc/de/RaumZeitLabor/PartKeepr/Part/Part.php | 47+++++++++++++++++++++++++++++++++++++++++++++--
Asrc/de/RaumZeitLabor/PartKeepr/Part/PartAttachment.php | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Part/PartImage.php | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartKeepr/Part/PartManager.php | 48++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartKeepr/Part/PartService.php | 4++++
Msrc/de/RaumZeitLabor/PartKeepr/PartDistributor/PartDistributorService.php | 2+-
Msrc/de/RaumZeitLabor/PartKeepr/PartKeepr.php | 2++
Asrc/de/RaumZeitLabor/PartKeepr/TempFile/TempFileService.php | 25+++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartKeepr/TempImage/TempImageService.php | 4+++-
Msrc/de/RaumZeitLabor/PartKeepr/UploadedFile/TempUploadedFile.php | 7+++++--
Msrc/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/de/RaumZeitLabor/PartKeepr/Util/Exceptions/EntityNotFoundException.php | 3++-
Mtesting/PartTest.php | 15+++------------
Mtesting/SetupDatabase.php | 25+++++++++++++++++++------
111 files changed, 650 insertions(+), 50 deletions(-)

diff --git a/frontend/file.php b/frontend/file.php @@ -0,0 +1,48 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Frontend; +use de\RaumZeitLabor\PartKeepr\Part\PartAttachment; + +use de\RaumZeitLabor\PartKeepr\UploadedFile\TempUploadedFile; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr; +use de\RaumZeitLabor\PartKeepr\Image\Image; +use de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo; + +include("../src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); + +PartKeepr::initialize(""); + +$type = $_REQUEST["type"]; +$id = $_REQUEST["id"]; + +try { + switch ($type) { + case "PartAttachment": + $file = PartAttachment::loadById($id); + break; + default: + $file = null; + // Add default image? + } + +} catch (\Exception $e) { + $file = null; + // Something bad happened +} + +if ($file == null) { + // Could not find the image, but maybe we want a temporary image? + if (array_key_exists("tmpId", $_REQUEST)) { + $file = TempUploadedFile::loadById($_REQUEST["tmpId"]); + } +} +header("Content-Type: ".$file->getMimeType()); + +$fp = fopen($file->getFilename(), "rb"); +fpassthru($fp); +fclose($fp); + +Netraver::getEM()->flush(); +exit();+ \ No newline at end of file diff --git a/frontend/image.php b/frontend/image.php @@ -1,6 +1,6 @@ <?php namespace de\RaumZeitLabor\PartKeepr\Frontend; -use de\RaumZeitLabor\PartKeepr\Image\TempImage; +use de\RaumZeitLabor\PartKeepr\TempImage\TempImage; declare(encoding = 'UTF-8'); @@ -16,16 +16,17 @@ $type = $_REQUEST["type"]; $id = $_REQUEST["id"]; try { - switch ($type) { case Image::IMAGE_ICLOGO: $image = ManufacturerICLogo::loadById($id); break; default: + $image = null; // Add default image? } } catch (\Exception $e) { + $image = null; // Something bad happened } @@ -36,7 +37,6 @@ if ($image == null) { } } - $file = $image->fitWithin($_REQUEST["w"],$_REQUEST["h"]); header("Content-Type: image/png"); diff --git a/frontend/js/Components/Part/PartAttachmentGrid.js b/frontend/js/Components/Part/PartAttachmentGrid.js @@ -0,0 +1,152 @@ +Ext.define('PartKeepr.PartAttachmentGrid', { + extend: 'Ext.grid.Panel', + alias: 'widget.PartAttachmentGrid', + border: false, + initComponent: function () { + this.store = Ext.create("Ext.data.Store", { + model: 'PartAttachment', + proxy: { + type: 'memory', + reader: { + type: 'json' + } + } + + }); + + this.editing = Ext.create('Ext.grid.plugin.CellEditing', { + clicksToEdit: 1 + }); + + this.plugins = [ this.editing ]; + + this.deleteButton = Ext.create("Ext.button.Button", { + text: i18n('Delete'), + disabled: true, + itemId: 'delete', + scope: this, + icon: 'resources/silkicons/delete.png', + handler: this.onDeleteClick + }); + + this.viewButton = Ext.create("Ext.button.Button", { + text: i18n("View"), + handler: this.onViewClick, + scope: this, + disabled: true + }); + + this.dockedItems = [{ + xtype: 'toolbar', + items: [{ + text: i18n('Add'), + scope: this, + icon: 'resources/silkicons/attach.png', + handler: this.onAddClick + }, + this.viewButton, + this.deleteButton + ] + }]; + + this.columns = [ + { + header: "", + dataIndex: 'extension', + width: 30, + renderer: function (val) { + return '<img src="resources/mimetypes/'+val+'.png"/>'; + } + }, + { + header: i18n("Filename"), + dataIndex: 'originalFilename', + width: 200 + }, + { + header: i18n("Size"), + dataIndex: 'size', + width: 80, + renderer: PartKeepr.bytesToSize + }, + { + header: i18n("Description"), + dataIndex: 'description', + flex: 0.4, + editor: { + xtype:'textfield', + allowBlank:true + } + } + ]; + + this.callParent(); + + this.getSelectionModel().on('selectionchange', this.onSelectChange, this); + this.on("itemdblclick", this.onDoubleClick, this); + }, + onDoubleClick: function (view, record) { + if (record) { + this.viewAttachment(record); + } + }, + onAddClick: function () { + var j = Ext.create("PartKeepr.FileUploadDialog"); + j.on("fileUploaded", this.onFileUploaded, this); + j.show(); + }, + onFileUploaded: function (response) { + this.editing.cancelEdit(); + + this.getStore().add({ + id: 0, + tmp_id: response.id, + extension: response.extension, + size: response.size, + originalFilename: response.originalFilename + }); + + }, + onDeleteClick: function () { + var selection = this.getView().getSelectionModel().getSelection()[0]; + if (selection) { + this.store.remove(selection); + } + }, + onSelectChange: function(selModel, selections){ + this.deleteButton.setDisabled(selections.length === 0); + this.viewButton.setDisabled(selections.length === 0); + }, + onViewClick: function () { + var selection = this.getView().getSelectionModel().getSelection()[0]; + if (selection) { + this.viewAttachment(selection); + } + }, + viewAttachment: function (record) { + var mySrc = "file.php?type=PartAttachment&"; + + if (record.get("id") == 0) { + mySrc += "id=0&tmpId=" + record.get("tmp_id"); + } else { + mySrc += "id=" + record.get("id"); + } + console.log(mySrc); + + new Ext.Window({ + title : i18n("Display File"), + width : 300, + height: 300, + maximizable: true, + constrain: true, + layout : 'fit', + items : [{ + xtype : "component", + autoEl : { + tag : "iframe", + src : mySrc + } + }] + }).show(); + } +});+ \ No newline at end of file diff --git a/frontend/js/Components/Part/PartEditor.js b/frontend/js/Components/Part/PartEditor.js @@ -57,6 +57,11 @@ Ext.define('PartKeepr.PartEditor', { layout: 'fit' }); + this.partAttachmentGrid = Ext.create("PartKeepr.PartAttachmentGrid", { + title: i18n("Attachments"), + layout: 'fit' + }); + this.items = { xtype: 'tabpanel', border: false, @@ -76,7 +81,8 @@ Ext.define('PartKeepr.PartEditor', { }, this.partDistributorGrid, this.partManufacturerGrid, - this.partParameterGrid + this.partParameterGrid, + this.partAttachmentGrid ] }; @@ -118,6 +124,13 @@ Ext.define('PartKeepr.PartEditor', { "updates": PartKeepr.serializeRecords(this.partParameterGrid.getStore().getUpdatedRecords()), "removals": PartKeepr.serializeRecords(this.partParameterGrid.getStore().getRemovedRecords()) }; + + values.attachmentChanges = { + "inserts": PartKeepr.serializeRecords(this.partAttachmentGrid.getStore().getNewRecords()), + "updates": PartKeepr.serializeRecords(this.partAttachmentGrid.getStore().getUpdatedRecords()), + "removals": PartKeepr.serializeRecords(this.partAttachmentGrid.getStore().getRemovedRecords()) + }; + call.setParameters(values); call.setHandler(Ext.bind(this.onPartSave, this)); call.doCall(); diff --git a/frontend/js/Components/Part/PartEditorWindow.js b/frontend/js/Components/Part/PartEditorWindow.js @@ -4,7 +4,7 @@ Ext.define('PartKeepr.PartEditorWindow', { width: 600, minWidth: 600, minHeight: 300, - height: 350, + height: 450, layout: 'fit', title: i18n("Add Part"), initComponent: function () { @@ -40,5 +40,6 @@ Ext.define('PartKeepr.PartEditorWindow', { this.editor.partDistributorGrid.getStore().loadData(r.distributors); this.editor.partManufacturerGrid.getStore().loadData(r.manufacturers); this.editor.partParameterGrid.getStore().loadData(r.parameters); + this.editor.partAttachmentGrid.getStore().loadData(r.attachments); } }); diff --git a/frontend/js/Models/PartAttachment.js b/frontend/js/Models/PartAttachment.js @@ -0,0 +1,14 @@ +PartKeepr.PartDistributor = Ext.define("PartAttachment", { + extend: "Ext.data.Model", + fields: [ + { id: 'id', name: 'id', type: 'int' }, + { name: 'originalFilename', type: 'string' }, + { name: 'mimetype', type: 'string' }, + { name: 'extension', type: 'string' }, + { name: 'description', type: 'string' }, + { name: 'size', type: 'string' }, + { name: 'tmp_id', type: 'int' } + ], + belongsTo: { type: 'belongsTo', model: 'Part', primaryKey: 'id', foreignKey: 'part_id'}, + proxy: PartKeepr.getRESTProxy("PartAttachment") +});+ \ No newline at end of file diff --git a/frontend/resources/mimetypes/7z.png b/frontend/resources/mimetypes/7z.png Binary files differ. diff --git a/frontend/resources/mimetypes/README b/frontend/resources/mimetypes/README @@ -0,0 +1,27 @@ +http://www.splitbrain.org/projects/file_icons + +Released to the Public Domain +Free to use. Provided as is. No warranties. + +Note: The big majority of icons where created by the creators listed + below. Only a few ones where found on the net. They were too + widespread to determine the original author and thus were + considered public domain. + If you are the author of one of those icons just send a short + mail to either be included in the list below or have the icon + removed from the package. + +Creators: + + Andreas Gohr <andi@splitbrain.org> + Michael Klier <chi@chimeric.de> + Andreas Barton <andreas.barton@web.de> + Hubert Chathi <hubert@uhoreg.ca> + Johan Koehne <johankohne@gmail.com> + Rudi von Staden <rudivs@iafrica.com> + Daniel Darvish <ddarvish@hibm.org> + Andy Pascall <apascall@engineering.ucsb.edu> + Seth <seth.holcomb@gmail.com> + David Carella <david.carella@gmail.com> + Tom N. Harris <telliamed@fastmail.us> + Brandon Carmon Colvin <b.carmon.colvin@gmail.com> diff --git a/frontend/resources/mimetypes/ai.png b/frontend/resources/mimetypes/ai.png Binary files differ. diff --git a/frontend/resources/mimetypes/aiff.png b/frontend/resources/mimetypes/aiff.png Binary files differ. diff --git a/frontend/resources/mimetypes/asc.png b/frontend/resources/mimetypes/asc.png Binary files differ. diff --git a/frontend/resources/mimetypes/audio.png b/frontend/resources/mimetypes/audio.png Binary files differ. diff --git a/frontend/resources/mimetypes/bin.png b/frontend/resources/mimetypes/bin.png Binary files differ. diff --git a/frontend/resources/mimetypes/bz2.png b/frontend/resources/mimetypes/bz2.png Binary files differ. diff --git a/frontend/resources/mimetypes/c.png b/frontend/resources/mimetypes/c.png Binary files differ. diff --git a/frontend/resources/mimetypes/cfc.png b/frontend/resources/mimetypes/cfc.png Binary files differ. diff --git a/frontend/resources/mimetypes/cfm.png b/frontend/resources/mimetypes/cfm.png Binary files differ. diff --git a/frontend/resources/mimetypes/chm.png b/frontend/resources/mimetypes/chm.png Binary files differ. diff --git a/frontend/resources/mimetypes/class.png b/frontend/resources/mimetypes/class.png Binary files differ. diff --git a/frontend/resources/mimetypes/conf.png b/frontend/resources/mimetypes/conf.png Binary files differ. diff --git a/frontend/resources/mimetypes/cpp.png b/frontend/resources/mimetypes/cpp.png Binary files differ. diff --git a/frontend/resources/mimetypes/cs.png b/frontend/resources/mimetypes/cs.png Binary files differ. diff --git a/frontend/resources/mimetypes/css.png b/frontend/resources/mimetypes/css.png Binary files differ. diff --git a/frontend/resources/mimetypes/csv.png b/frontend/resources/mimetypes/csv.png Binary files differ. diff --git a/frontend/resources/mimetypes/deb.png b/frontend/resources/mimetypes/deb.png Binary files differ. diff --git a/frontend/resources/mimetypes/divx.png b/frontend/resources/mimetypes/divx.png Binary files differ. diff --git a/frontend/resources/mimetypes/doc.png b/frontend/resources/mimetypes/doc.png Binary files differ. diff --git a/frontend/resources/mimetypes/dot.png b/frontend/resources/mimetypes/dot.png Binary files differ. diff --git a/frontend/resources/mimetypes/eml.png b/frontend/resources/mimetypes/eml.png Binary files differ. diff --git a/frontend/resources/mimetypes/enc.png b/frontend/resources/mimetypes/enc.png Binary files differ. diff --git a/frontend/resources/mimetypes/file.png b/frontend/resources/mimetypes/file.png Binary files differ. diff --git a/frontend/resources/mimetypes/gif.png b/frontend/resources/mimetypes/gif.png Binary files differ. diff --git a/frontend/resources/mimetypes/gz.png b/frontend/resources/mimetypes/gz.png Binary files differ. diff --git a/frontend/resources/mimetypes/hlp.png b/frontend/resources/mimetypes/hlp.png Binary files differ. diff --git a/frontend/resources/mimetypes/htm.png b/frontend/resources/mimetypes/htm.png Binary files differ. diff --git a/frontend/resources/mimetypes/html.png b/frontend/resources/mimetypes/html.png Binary files differ. diff --git a/frontend/resources/mimetypes/image.png b/frontend/resources/mimetypes/image.png Binary files differ. diff --git a/frontend/resources/mimetypes/iso.png b/frontend/resources/mimetypes/iso.png Binary files differ. diff --git a/frontend/resources/mimetypes/jar.png b/frontend/resources/mimetypes/jar.png Binary files differ. diff --git a/frontend/resources/mimetypes/java.png b/frontend/resources/mimetypes/java.png Binary files differ. diff --git a/frontend/resources/mimetypes/jpeg.png b/frontend/resources/mimetypes/jpeg.png Binary files differ. diff --git a/frontend/resources/mimetypes/jpg.png b/frontend/resources/mimetypes/jpg.png Binary files differ. diff --git a/frontend/resources/mimetypes/js.png b/frontend/resources/mimetypes/js.png Binary files differ. diff --git a/frontend/resources/mimetypes/lua.png b/frontend/resources/mimetypes/lua.png Binary files differ. diff --git a/frontend/resources/mimetypes/m.png b/frontend/resources/mimetypes/m.png Binary files differ. diff --git a/frontend/resources/mimetypes/mm.png b/frontend/resources/mimetypes/mm.png Binary files differ. diff --git a/frontend/resources/mimetypes/mov.png b/frontend/resources/mimetypes/mov.png Binary files differ. diff --git a/frontend/resources/mimetypes/mp3.png b/frontend/resources/mimetypes/mp3.png Binary files differ. diff --git a/frontend/resources/mimetypes/mpg.png b/frontend/resources/mimetypes/mpg.png Binary files differ. diff --git a/frontend/resources/mimetypes/odc.png b/frontend/resources/mimetypes/odc.png Binary files differ. diff --git a/frontend/resources/mimetypes/odf.png b/frontend/resources/mimetypes/odf.png Binary files differ. diff --git a/frontend/resources/mimetypes/odg.png b/frontend/resources/mimetypes/odg.png Binary files differ. diff --git a/frontend/resources/mimetypes/odi.png b/frontend/resources/mimetypes/odi.png Binary files differ. diff --git a/frontend/resources/mimetypes/odp.png b/frontend/resources/mimetypes/odp.png Binary files differ. diff --git a/frontend/resources/mimetypes/ods.png b/frontend/resources/mimetypes/ods.png Binary files differ. diff --git a/frontend/resources/mimetypes/odt.png b/frontend/resources/mimetypes/odt.png Binary files differ. diff --git a/frontend/resources/mimetypes/ogg.png b/frontend/resources/mimetypes/ogg.png Binary files differ. diff --git a/frontend/resources/mimetypes/pdf.png b/frontend/resources/mimetypes/pdf.png Binary files differ. diff --git a/frontend/resources/mimetypes/pgp.png b/frontend/resources/mimetypes/pgp.png Binary files differ. diff --git a/frontend/resources/mimetypes/php.png b/frontend/resources/mimetypes/php.png Binary files differ. diff --git a/frontend/resources/mimetypes/pl.png b/frontend/resources/mimetypes/pl.png Binary files differ. diff --git a/frontend/resources/mimetypes/png.png b/frontend/resources/mimetypes/png.png Binary files differ. diff --git a/frontend/resources/mimetypes/ppt.png b/frontend/resources/mimetypes/ppt.png Binary files differ. diff --git a/frontend/resources/mimetypes/ps.png b/frontend/resources/mimetypes/ps.png Binary files differ. diff --git a/frontend/resources/mimetypes/py.png b/frontend/resources/mimetypes/py.png Binary files differ. diff --git a/frontend/resources/mimetypes/ram.png b/frontend/resources/mimetypes/ram.png Binary files differ. diff --git a/frontend/resources/mimetypes/rar.png b/frontend/resources/mimetypes/rar.png Binary files differ. diff --git a/frontend/resources/mimetypes/rb.png b/frontend/resources/mimetypes/rb.png Binary files differ. diff --git a/frontend/resources/mimetypes/rm.png b/frontend/resources/mimetypes/rm.png Binary files differ. diff --git a/frontend/resources/mimetypes/rpm.png b/frontend/resources/mimetypes/rpm.png Binary files differ. diff --git a/frontend/resources/mimetypes/rtf.png b/frontend/resources/mimetypes/rtf.png Binary files differ. diff --git a/frontend/resources/mimetypes/sig.png b/frontend/resources/mimetypes/sig.png Binary files differ. diff --git a/frontend/resources/mimetypes/sql.png b/frontend/resources/mimetypes/sql.png Binary files differ. diff --git a/frontend/resources/mimetypes/swf.png b/frontend/resources/mimetypes/swf.png Binary files differ. diff --git a/frontend/resources/mimetypes/sxc.png b/frontend/resources/mimetypes/sxc.png Binary files differ. diff --git a/frontend/resources/mimetypes/sxd.png b/frontend/resources/mimetypes/sxd.png Binary files differ. diff --git a/frontend/resources/mimetypes/sxi.png b/frontend/resources/mimetypes/sxi.png Binary files differ. diff --git a/frontend/resources/mimetypes/sxw.png b/frontend/resources/mimetypes/sxw.png Binary files differ. diff --git a/frontend/resources/mimetypes/tar.png b/frontend/resources/mimetypes/tar.png Binary files differ. diff --git a/frontend/resources/mimetypes/tex.png b/frontend/resources/mimetypes/tex.png Binary files differ. diff --git a/frontend/resources/mimetypes/tgz.png b/frontend/resources/mimetypes/tgz.png Binary files differ. diff --git a/frontend/resources/mimetypes/txt.png b/frontend/resources/mimetypes/txt.png Binary files differ. diff --git a/frontend/resources/mimetypes/vcf.png b/frontend/resources/mimetypes/vcf.png Binary files differ. diff --git a/frontend/resources/mimetypes/video.png b/frontend/resources/mimetypes/video.png Binary files differ. diff --git a/frontend/resources/mimetypes/vsd.png b/frontend/resources/mimetypes/vsd.png Binary files differ. diff --git a/frontend/resources/mimetypes/wav.png b/frontend/resources/mimetypes/wav.png Binary files differ. diff --git a/frontend/resources/mimetypes/wma.png b/frontend/resources/mimetypes/wma.png Binary files differ. diff --git a/frontend/resources/mimetypes/wmv.png b/frontend/resources/mimetypes/wmv.png Binary files differ. diff --git a/frontend/resources/mimetypes/xls.png b/frontend/resources/mimetypes/xls.png Binary files differ. diff --git a/frontend/resources/mimetypes/xml.png b/frontend/resources/mimetypes/xml.png Binary files differ. diff --git a/frontend/resources/mimetypes/xpi.png b/frontend/resources/mimetypes/xpi.png Binary files differ. diff --git a/frontend/resources/mimetypes/xvid.png b/frontend/resources/mimetypes/xvid.png Binary files differ. diff --git a/frontend/resources/mimetypes/zip.png b/frontend/resources/mimetypes/zip.png Binary files differ. diff --git a/frontend/upload.php b/frontend/upload.php @@ -14,6 +14,7 @@ PartKeepr::initialize(""); $keys = array_keys($_FILES); $file = $_FILES[$keys[0]]["tmp_name"]; +$filename = $_FILES[$keys[0]]["name"]; switch ($_REQUEST["uploadMode"]) { case "image": @@ -25,6 +26,7 @@ switch ($_REQUEST["uploadMode"]) { $image = new ManufacturerICLogo(); $image->setManufacturer($manufacturer); $image->replace($file); + $image->setOriginalFilename(basename($filename)); PartKeepr::getEM()->persist($image); PartKeepr::getEM()->flush(); } diff --git a/src/de/RaumZeitLabor/PartKeepr/Footprint/FootprintManager.php b/src/de/RaumZeitLabor/PartKeepr/Footprint/FootprintManager.php @@ -112,20 +112,19 @@ class FootprintManager extends Singleton { * @param mixed $footprint Either the ID or the footprint's name to find */ public function getOrCreateFootprint ($footprint) { - if (is_int($footprint)) { - try { - Footprint::loadById($footprint); - } catch (EntityNotFoundException $e) {} - } else { - $dql = "SELECT f FROM de\RaumZeitLabor\PartKeepr\Footprint\Footprint f WHERE f.name = :name"; - $query = PartKeepr::getEM()->createQuery($dql); - $query->setParameter("name", $footprint); + try { + $footprint = Footprint::loadById($footprint); + return $footprint; + } catch (EntityNotFoundException $e) {} + + $dql = "SELECT f FROM de\RaumZeitLabor\PartKeepr\Footprint\Footprint f WHERE f.name = :name"; + $query = PartKeepr::getEM()->createQuery($dql); + $query->setParameter("name", $footprint); - try { - $footprint = $query->getSingleResult(); - return $footprint; - } catch (\Exception $e) {} - } + try { + $footprint = $query->getSingleResult(); + return $footprint; + } catch (\Exception $e) {} $fp = new Footprint(); $fp->setName($footprint); @@ -134,4 +133,4 @@ class FootprintManager extends Singleton { return $fp; } -}- \ No newline at end of file +} diff --git a/src/de/RaumZeitLabor/PartKeepr/Image/Image.php b/src/de/RaumZeitLabor/PartKeepr/Image/Image.php @@ -13,6 +13,7 @@ use de\RaumZeitLabor\PartKeepr\PartKeepr, abstract class Image extends UploadedFile { const IMAGE_ICLOGO = "iclogo"; const IMAGE_TEMP = "temp"; + const IMAGE_PART = "part"; /** * Constructs a new image object. @@ -35,6 +36,7 @@ abstract class Image extends UploadedFile { switch ($type) { case Image::IMAGE_ICLOGO: case Image::IMAGE_TEMP: + case Image::IMAGE_PART: parent::setType($type); break; default: @@ -198,4 +200,4 @@ abstract class Image extends UploadedFile { } } -}- \ No newline at end of file +} diff --git a/src/de/RaumZeitLabor/PartKeepr/ManufacturerICLogo/ManufacturerICLogoService.php b/src/de/RaumZeitLabor/PartKeepr/ManufacturerICLogo/ManufacturerICLogoService.php @@ -71,7 +71,8 @@ class ManufacturerICLogoService extends Service implements RestfulService { $manufacturer = Manufacturer::loadById($this->getParameter("manufacturer_id")); $image->setManufacturer($manufacturer); - $image->replace($tmpImage->getImageFilename()); + $image->replace($tmpImage->getFilename()); + $image->setOriginalFilename($tmpImage->getOriginalFilename()); PartKeepr::getEM()->persist($image); PartKeepr::getEM()->flush(); diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/Part.php b/src/de/RaumZeitLabor/PartKeepr/Part/Part.php @@ -65,6 +65,20 @@ class Part extends BaseEntity implements Serializable { private $distributors; /** + * Holds the part images + * @OneToMany(targetEntity="de\RaumZeitLabor\PartKeepr\Part\PartImage",mappedBy="part",cascade={"persist", "remove"}) + * @var PartImage + */ + private $images; + + /** + * Holds the part attachments + * @OneToMany(targetEntity="de\RaumZeitLabor\PartKeepr\Part\PartAttachment",mappedBy="part",cascade={"persist", "remove"}) + * @var PartAttachment + */ + private $attachments; + + /** * The comment for this part * @Column(type="text") */ @@ -114,6 +128,8 @@ class Part extends BaseEntity implements Serializable { $this->distributors = new \Doctrine\Common\Collections\ArrayCollection(); $this->manufacturers = new \Doctrine\Common\Collections\ArrayCollection(); $this->parameters = new \Doctrine\Common\Collections\ArrayCollection(); + $this->images = new \Doctrine\Common\Collections\ArrayCollection(); + $this->attachments = new \Doctrine\Common\Collections\ArrayCollection(); } /** @@ -236,6 +252,22 @@ class Part extends BaseEntity implements Serializable { } /** + * Returns the part images array + * @return ArrayCollection the part images + */ + public function getImages () { + return $this->images; + } + + /** + * Returns the part attachments array + * @return ArrayCollection the part attachments + */ + public function getAttachments () { + return $this->attachments; + } + + /** * Returns the manufacturers array * @return ArrayCollection the manufactuers */ @@ -285,6 +317,16 @@ class Part extends BaseEntity implements Serializable { $aParameters[] = $parameter->serialize(); } + $aImages = array(); + foreach ($this->getImages() as $image) { + $aImages[] = $image->serialize(); + } + + $aAttachments = array(); + foreach ($this->getAttachments() as $attachment) { + $aAttachments[] = $attachment->serialize(); + } + return array( "id" => $this->getId(), "name" => $this->getName(), @@ -300,8 +342,10 @@ class Part extends BaseEntity implements Serializable { "partUnit_shortName" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : "", "manufacturers" => $aManufacturers, "distributors" => $aDistributors, + "images" => $aImages, + "attachments" => $aAttachments, "parameters" => $aParameters ); } -}- \ No newline at end of file +} diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartAttachment.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartAttachment.php @@ -0,0 +1,82 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Part; +use de\RaumZeitLabor\PartKeepr\Util\Serializable; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\UploadedFile\UploadedFile; + +/** + * Holds a part attachment + * @Entity + **/ +class PartAttachment extends UploadedFile implements Serializable { + /** + * The description of this attachment + * @Column(type="text") + * @var string + */ + private $description; + + /** + * Creates a new part attachment + */ + public function __construct () { + parent::__construct(); + $this->setType("PartAttachment"); + } + /** + * The part object + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Part\Part") + * @var Part + */ + private $part = null; + + /** + * Sets the part + * @param Part $part The part to set + */ + public function setPart (Part $part) { + $this->part = $part; + } + + /** + * Returns the part + * @return Part the part + */ + public function getPart () { + return $this->part; + } + + /** + * Sets the description for this attachment + * @param string $description The attachment description + */ + public function setDescription ($description) { + $this->description = $description; + } + + /** + * Returns the description for this attachment + * @return string The description + */ + public function getDescription () { + return $this->description; + } + + /** + * + * Serializes this part attachment + * @return array The serialized part attachment + */ + public function serialize () { + return array( + "id" => $this->getId(), + "part_id" => $this->getPart()->getId(), + "originalFilename" => $this->getOriginalFilename(), + "mimetype" => $this->getMimetype(), + "extension" => $this->getExtension(), + "size" => $this->getSize(), + "description" => $this->getDescription()); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartImage.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartImage.php @@ -0,0 +1,52 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Part; +use de\RaumZeitLabor\PartKeepr\Util\Serializable; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Image\Image; + +/** + * Holds a part image + * @Entity + **/ +class PartImage extends Image implements Serializable { + /** + * The part object + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Part\Part") + * @var Part + */ + private $part = null; + + /** + * Creates a new part image instance + */ + public function __construct () { + parent::__construct(Image::IMAGE_PART); + } + + /** + * Sets the part + * @param Part $part The part to set + */ + public function setPart (Part $part) { + $this->part = $part; + } + + /** + * Returns the part + * @return Part the part + */ + public function getPart () { + return $this->part; + } + + /** + * + * Serializes this part image + * @return array The serialized part imaage + */ + public function serialize () { + return array("id" => $this->getId(), "part_id" => $this->getPart()->getId()); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartManager.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartManager.php @@ -1,5 +1,7 @@ <?php namespace de\raumzeitlabor\PartKeepr\Part; +use de\RaumZeitLabor\PartKeepr\UploadedFile\TempUploadedFile; + use de\RaumZeitLabor\PartKeepr\PartParameter\PartParameter; use de\RaumZeitLabor\PartKeepr\Unit\Unit; @@ -198,6 +200,12 @@ class PartManager extends Singleton { } } + if (array_key_exists("attachmentChanges", $aParameters)) { + if (is_array($aParameters["attachmentChanges"])) { + $this->processAttachmentChanges($part, $aParameters["attachmentChanges"]); + } + } + if (array_key_exists("partUnit", $aParameters)) { if ($aParameters["partUnit"] === null || $aParameters["partUnit"] === 0) { $part->setPartUnit(null); @@ -328,6 +336,46 @@ class PartManager extends Singleton { } } + private function processAttachmentChanges (Part $part, Array $data) { + if (array_key_exists("updates", $data)) { + foreach ($data["updates"] as $record) { + foreach ($part->getAttachments() as $partAttachment) { + if ($partAttachment->getId() == $record["id"]) { + $partAttachment->setDescription($record["description"]); + break; + } + } + } + } + + if (array_key_exists("removals", $data)) { + foreach ($data["removals"] as $record) { + foreach ($part->getAttachments() as $partAttachment) { + if ($partAttachment->getId() == $record["id"]) { + PartKeepr::getEM()->remove($partAttachment); + $part->getAttachments()->removeElement($partAttachment); + break; + } + } + } + } + + if (array_key_exists("inserts", $data)) { + foreach ($data["inserts"] as $record) { + $attachment = new PartAttachment(); + $attachment->setPart($part); + $attachment->setDescription($record["description"]); + + $file = TempUploadedFile::loadById($record["tmp_id"]); + + $attachment->replace($file->getFilename()); + $attachment->setOriginalFilename($file->getOriginalFilename()); + + $part->getAttachments()->add($attachment); + } + } + } + public function deletePart ($id) { $part = PartManager::getInstance()->getPart($id); diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartService.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartService.php @@ -139,6 +139,10 @@ class PartService extends Service implements RestfulService { $aParameters["parameterChanges"] = $this->getParameter("parameterChanges"); } + if ($this->hasParameter("attachmentChanges")) { + $aParameters["attachmentChanges"] = $this->getParameter("attachmentChanges"); + } + if ($this->hasParameter("partUnit_id")) { $aParameters["partUnit"] = $this->getParameter("partUnit_id"); } diff --git a/src/de/RaumZeitLabor/PartKeepr/PartDistributor/PartDistributorService.php b/src/de/RaumZeitLabor/PartKeepr/PartDistributor/PartDistributorService.php @@ -62,7 +62,7 @@ class PartDistributorService extends Service implements RestfulService { $manufacturer = Manufacturer::loadById($this->getParameter("manufacturer_id")); $image->setManufacturer($manufacturer); - $image->replace($tmpImage->getImageFilename()); + $image->replace($tmpImage->getFilename()); PartKeepr::getEM()->persist($image); PartKeepr::getEM()->flush(); diff --git a/src/de/RaumZeitLabor/PartKeepr/PartKeepr.php b/src/de/RaumZeitLabor/PartKeepr/PartKeepr.php @@ -178,6 +178,8 @@ class PartKeepr { 'de\RaumZeitLabor\PartKeepr\Part\PartUnit', 'de\RaumZeitLabor\PartKeepr\Part\PartManufacturer', 'de\RaumZeitLabor\PartKeepr\Part\PartDistributor', + 'de\RaumZeitLabor\PartKeepr\Part\PartImage', + 'de\RaumZeitLabor\PartKeepr\Part\PartAttachment', 'de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation', 'de\RaumZeitLabor\PartKeepr\Stock\StockEntry', 'de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer', diff --git a/src/de/RaumZeitLabor/PartKeepr/TempFile/TempFileService.php b/src/de/RaumZeitLabor/PartKeepr/TempFile/TempFileService.php @@ -0,0 +1,24 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\TempFile; + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\UploadedFile\TempUploadedFile; +use de\RaumZeitLabor\PartKeepr\PartKeepr; + +class TempFileService extends Service { + + public function upload () { + $tmpFile = new TempUploadedFile(); + + $file = $_FILES['userfile']['tmp_name']; + $filename = $_FILES['userfile']['name']; + + $tmpFile->replace($file); + $tmpFile->setOriginalFilename(basename($filename)); + PartKeepr::getEM()->persist($tmpFile); + PartKeepr::getEM()->flush(); + + return array("id" => $tmpFile->getId(), "extension" => $tmpFile->getExtension(), "size" => $tmpFile->getSize(), "originalFilename" => $tmpFile->getOriginalFilename()); + } +} + + \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/TempImage/TempImageService.php b/src/de/RaumZeitLabor/PartKeepr/TempImage/TempImageService.php @@ -2,7 +2,7 @@ namespace de\RaumZeitLabor\PartKeepr\TempImage; use de\RaumZeitLabor\PartKeepr\Service\Service; -use de\RaumZeitLabor\PartKeepr\Image\TempImage; +use de\RaumZeitLabor\PartKeepr\TempImage\TempImage; use de\RaumZeitLabor\PartKeepr\PartKeepr; class TempImageService extends Service { @@ -11,8 +11,10 @@ class TempImageService extends Service { $image = new TempImage(); $file = $_FILES['userfile']['tmp_name']; + $filename = $_FILES['userfile']['name']; $image->replace($file); + $image->setOriginalFilename(basename($filename)); PartKeepr::getEM()->persist($image); PartKeepr::getEM()->flush(); diff --git a/src/de/RaumZeitLabor/PartKeepr/UploadedFile/TempUploadedFile.php b/src/de/RaumZeitLabor/PartKeepr/UploadedFile/TempUploadedFile.php @@ -9,4 +9,8 @@ declare(encoding = 'UTF-8'); * @Entity */ class TempUploadedFile extends UploadedFile { -}- \ No newline at end of file + public function __construct () { + parent::__construct(); + $this->setType("Temporary"); + } +} diff --git a/src/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php b/src/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php @@ -28,6 +28,13 @@ abstract class UploadedFile extends BaseEntity { private $filename; /** + * The original name of the file + * @Column(type="string",nullable=true) + * @var string + */ + private $originalname; + + /** * The mimetype for the file * @var string * @Column(type="string") @@ -58,6 +65,22 @@ abstract class UploadedFile extends BaseEntity { } /** + * Returns the original filename + * @return string The original filename + */ + public function getOriginalFilename () { + return $this->originalname; + } + + /** + * Sets the original filename + * @param string $filename The original filename + */ + public function setOriginalFilename ($filename) { + $this->originalname = $filename; + } + + /** * Replaces the current file with a new file. * * @param string $path The path to the original file @@ -75,6 +98,56 @@ abstract class UploadedFile extends BaseEntity { } /** + * Replaces the file from an URL. Does some tricks to avoid 403 forbidden on some sites. + * @param string $url + */ + public function replaceFromURL ($url) { + + /* Some sites don't like automated requests. But the internet is meant to be open for anybody, + * even for scripts. So we are evil and fake the headers. + * + * Credit goes to Ryan Rampersad from whom I copied most code. + * http://blog.ryanrampersad.com/2008/11/07/get-remote-html-with-curl-and-php/ + */ + $curl = curl_init(); + + $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; + $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; + $header[] = "Cache-Control: max-age=0"; + $header[] = "Connection: keep-alive"; + $header[] = "Keep-Alive: 300"; + $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; + $header[] = "Accept-Language: en-us,en;q=0.5"; + $header[] = "Pragma: "; + + $browser = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092510 Ubuntu/8.04 (hardy) Firefox/3.0.3"; + + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_USERAGENT, $browser); + curl_setopt($curl, CURLOPT_HTTPHEADER, $header); + curl_setopt($curl, CURLOPT_AUTOREFERER, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_TIMEOUT, 30); + curl_setopt($curl, CURLOPT_MAXREDIRS, 7); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + + $data = curl_exec($curl); + curl_close($curl); + + if ($data === false) { + throw new \Exception("replaceFromURL error: ".curl_error($curl)); + } + + $tempName = tempnam("/tmp", "PARTKEEPR"); + + file_put_contents($tempName, $data); + + $this->replace($tempName); + + $this->setOriginalFilename(basename($url)); + } + + /** * Returns the size of this file * @return integer The size in bytes */ @@ -154,4 +227,4 @@ abstract class UploadedFile extends BaseEntity { mkdir($this->getFilePath(), 0777, true); } } -}- \ No newline at end of file +} diff --git a/src/de/RaumZeitLabor/PartKeepr/Util/Exceptions/EntityNotFoundException.php b/src/de/RaumZeitLabor/PartKeepr/Util/Exceptions/EntityNotFoundException.php @@ -2,7 +2,8 @@ namespace de\RaumZeitLabor\PartKeepr\Util\Exceptions; declare(encoding = 'UTF-8'); -use de\RaumZeitLabor\PartKeepr\Util\SerializableException; +use de\RaumZeitLabor\PartKeepr\Util\SerializableException, + de\RaumZeitLabor\PartKeepr\PartKeepr; /** * Thrown when an entity via loadById() was not found. diff --git a/testing/PartTest.php b/testing/PartTest.php @@ -11,17 +11,9 @@ use de\RaumZeitLabor\PartKeepr\Category\Category; use de\RaumZeitLabor\PartKeepr\Category\CategoryManager; use de\RaumZeitLabor\PartKeepr\PartKeepr; use de\RaumZeitLabor\PartKeepr\Part\Part; +use de\RaumZeitLabor\PartKeepr\Part\PartAttachment; PartKeepr::initialize(); -$category = CategoryManager::getInstance()->getCategory(2); -$footprint = FootprintManager::getInstance()->getFootprint(2); - -$part = new Part(); -$part->setFootprint($footprint); -$part->setCategory($category->getNode()); -$part->setName("Tolles Bauteil"); -$part->setComment("0815 zeugs"); - -PartKeepr::getEM()->persist($part); -PartKeepr::getEM()->flush();- \ No newline at end of file +$test = new PartAttachment(); +$test->replaceFromURL("http://www.datasheetcatalog.org/datasheet/motorola/MCT7809BD2T.pdf"); diff --git a/testing/SetupDatabase.php b/testing/SetupDatabase.php @@ -1,6 +1,7 @@ <?php namespace de\RaumZeitLabor\PartKeepr\Tests; use de\RaumZeitLabor\PartKeepr\PartParameter\PartParameter; +use de\RaumZeitLabor\PartKeepr\Part\PartAttachment; declare(encoding = 'UTF-8'); @@ -58,10 +59,9 @@ if (!($_SERVER["argc"] == 2 && $_SERVER["argv"][1] == "--yes")) { echo "Performing actions...\n"; -@mkdir("../src/Proxies"); -@mkdir("../data"); -@mkdir("../data/images"); -chmod("../src/Proxies", 0777); +mkdir("../src/Proxies"); +mkdir("../data"); +mkdir("../data/images"); chmod("../data/images", 0777); $tool = new \Doctrine\ORM\Tools\SchemaTool(PartKeepr::getEM()); @@ -225,6 +225,7 @@ foreach ($data as $mfgname => $logos) { $mfglogo = new ManufacturerICLogo(); $mfglogo->setManufacturer($manufacturer); $mfglogo->replace("../setup/data/manufacturers/images/".$logo); + $mfglogo->setOriginalFilename($logo); PartKeepr::getEM()->persist($mfglogo); } @@ -264,6 +265,20 @@ while ($part = mysql_fetch_assoc($r)) { $oPart->getDistributors()->add(new PartDistributor($oPart, $aDistributors[$part["id_supplier"]])); //echo "Migrating part ".sprintf("%-40s", $part["name"])."\r"; + + /* Add existing datasheets */ + $datasheetQuery = "SELECT datasheeturl FROM datasheets WHERE part_id = ".$part["id"]; + $r3 = mysql_query($datasheetQuery); + while ($res = mysql_fetch_assoc($r3)) { + $attachment = new PartAttachment(); + $attachment->setPart($oPart); + $attachment->replaceFromURL($res["datasheeturl"]); + $attachment->setDescription(PartKeepr::i18n("Datasheet")); + $oPart->getAttachments()->add($attachment); + + + } + PartKeepr::getEM()->persist($oPart); $oStock = new StockEntry($oPart, $part["instock"]); @@ -282,8 +297,6 @@ while ($part = mysql_fetch_assoc($r)) { PartKeepr::getEM()->persist($oStock); /* Add some random parameters */ - - for ($i=0;$i<rand(1,15);$i++) { $val = rand(0,999); $prefix = $aSiPrefixes[array_rand($aSiPrefixes)];