Index: branches/RC/kernel/constants.php
===================================================================
diff -u
--- branches/RC/kernel/constants.php (revision 0)
+++ branches/RC/kernel/constants.php (revision 9598)
@@ -0,0 +1,5 @@
+
\ No newline at end of file
Index: branches/RC/themes/default2007/platform/elements/forms.tpl
===================================================================
diff -u -r9248 -r9598
--- branches/RC/themes/default2007/platform/elements/forms.tpl (.../forms.tpl) (revision 9248)
+++ branches/RC/themes/default2007/platform/elements/forms.tpl (.../forms.tpl) (revision 9598)
@@ -159,6 +159,37 @@
+
+
">
+
+
+
+
+
+
+ ">
+
+
+
+
+
+ " tabindex="" style="">
+ [upload]" value="" />
+ |
+
+
+
+
" id="" value="" />
@@ -300,28 +331,28 @@
">
-
+
-
+
" id="_select" style="">
-
+
" onclick="$ItemCategories.AddCategory('» ', $delete_button, );"/>
-
-
+
+
Index: branches/RC/core/units/general/cat_tag_processor.php
===================================================================
diff -u -r9535 -r9598
--- branches/RC/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 9535)
+++ branches/RC/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 9598)
@@ -631,6 +631,13 @@
return $ret;
}
+
+ function DownloadFileLink($params)
+ {
+ $params[$this->getPrefixSpecial().'_event'] = 'OnDownloadFile';
+
+ return $this->ItemLink($params);
+ }
}
?>
\ No newline at end of file
Index: branches/RC/core/units/files/file_eh.php
===================================================================
diff -u -r9581 -r9598
--- branches/RC/core/units/files/file_eh.php (.../file_eh.php) (revision 9581)
+++ branches/RC/core/units/files/file_eh.php (.../file_eh.php) (revision 9598)
@@ -23,17 +23,6 @@
*/
function OnBeforeItemCreate(&$event)
{
- parent::OnBeforeItemCreate($event);
-
- $object =& $event->getObject();
-
- $this->resetPrimary($object);
-
- if (!$this->primaryFileFound($object)) {
- $object->SetDBField('IsPrimary', 1);
- $object->SetDBField('Status', STATUS_ACTIVE);
- }
-
$object->SetDBField('CreatedById', $this->Application->RecallVar('user_id'));
}
@@ -46,99 +35,11 @@
{
$object =& $event->getObject();
- $this->resetPrimary($object);
-
if (!$object->GetDBField('FileName')) {
$object->SetDBField('FileName', basename($object->GetDBField('FilePath')));
}
}
- /**
- * Checks for primary file along all files with same main item
- *
- * @param kDBItem $object
- * @return int
- */
- function primaryFileFound(&$object)
- {
- $sql = 'SELECT '.$object->IDField.'
- FROM '.$object->TableName.'
- WHERE (IsPrimary = 1) AND ('.$this->getParentClause($object).')';
- return $this->Conn->GetOne($sql);
- }
-
- /**
- * Resets primary mark from all item files
- *
- * @param kDBItem $object
- */
- function resetPrimary(&$object)
- {
- if (!$object->GetDBField('IsPrimary')) {
- return ;
- }
-
- $sql = 'UPDATE '.$object->TableName.'
- SET IsPrimary = 0
- WHERE '.$this->getParentClause($object);
- $this->Conn->Query($sql);
-
- $object->SetDBField('Status', STATUS_ACTIVE);
- }
-
- /**
- * Makes selected file primary
- *
- * @param kEvent $event
- */
- function OnSetPrimary(&$event)
- {
- $ids = $this->StoreSelectedIDs($event);
- if (!$ids) {
- return ;
- }
-
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $object->Load( array_shift($ids) );
-
- $object->SetDBField('IsPrimary', 1);
- $object->Update();
-
- $this->clearSelectedIDs($event);
- }
-
- /**
- * Don't allow to delete other user's messages
- *
- * @param kEvent $event
- */
- function customProcessing(&$event, $type)
- {
- parent::customProcessing($event, $type);
- if ($event->Name == 'OnMassDelete' && $type == 'before') {
- $ids = $event->getEventParam('ids');
- if ($ids) {
- $object =& $event->getObject();
- /* @var $object kDBItem */
-
- $primary_file_id = $this->primaryFileFound($object);
- if ($primary_file_id && ($primary_index = array_search($primary_file_id, $ids))) {
- $sql = 'SELECT COUNT(*)
- FROM '.$object->TableName.'
- WHERE (IsPrimary = 0) AND ('.$this->getParentClause($object).')';
- $non_primary_found = $this->Conn->Query($sql);
-
- if ($non_primary_found) {
- // non-primary files found for same main item -> don't delete primary file until all non-primary files are deleted
- unset($ids[$primary_index]);
- }
- }
-
- $event->setEventParam('ids', $ids);
- }
- }
- }
-
function SetCustomQuery(&$event)
{
parent::SetCustomQuery($event);
@@ -149,18 +50,6 @@
$object->addFilter('active_filter', '%1$s.Status = '.STATUS_ACTIVE);
}
}
-
- /**
- * Returns sql clause, that links file to it's parent item
- *
- * @param kDBItem $object
- * @return string
- */
- function getParentClause(&$object)
- {
- $parent_info = $object->getLinkedInfo($object->Special);
- return $parent_info['ForeignKey'].' = '.$parent_info['ParentId'];
- }
}
?>
\ No newline at end of file
Index: branches/RC/admin/install/inportal_schema.sql
===================================================================
diff -u -r9581 -r9598
--- branches/RC/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 9581)
+++ branches/RC/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 9598)
@@ -116,8 +116,6 @@
FilePath varchar(255) NOT NULL default '',
Size int(11) NOT NULL default '0',
`Status` tinyint(4) NOT NULL default '0',
- IsPrimary tinyint(4) NOT NULL default '0',
- Priority smallint(6) NOT NULL default '0',
CreatedOn int(11) unsigned NOT NULL default '0',
CreatedById int(11) NOT NULL default '-1',
MimeType varchar(255) NOT NULL default '',
Index: branches/RC/core/units/files/files_config.php
===================================================================
diff -u -r9581 -r9598
--- branches/RC/core/units/files/files_config.php (.../files_config.php) (revision 9581)
+++ branches/RC/core/units/files/files_config.php (.../files_config.php) (revision 9598)
@@ -63,7 +63,7 @@
'not_null' => 1, 'required' => 1, 'default' => ''
),
'Size' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
- 'Status' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Enabled', 0 => 'la_Disabled'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 0),
+ 'Status' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Enabled', 0 => 'la_Disabled'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 1),
'IsPrimary' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'Priority' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'CreatedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'not_null' => 1, 'default' => '#NOW#'),
Index: branches/RC/core/units/general/helpers/image_helper.php
===================================================================
diff -u -r9278 -r9598
--- branches/RC/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 9278)
+++ branches/RC/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 9598)
@@ -197,80 +197,6 @@
}
/**
- * Determines what image fields should be created (from post or just dummy fields for 1st upload)
- *
- * @param string $prefix
- */
- function createItemImages($prefix)
- {
- $items_info = $this->Application->GetVar($prefix);
- if ($items_info) {
- list ($id, $fields_values) = each($items_info);
- $this->createImageFields($prefix, $fields_values);
- }
- else {
- $this->createImageFields($prefix, Array());
- }
- }
-
- /**
- * Dynamically creates virtual fields for item for each image field in submit
- *
- * @param string $prefix
- * @param Array $fields_values
- */
- function createImageFields($prefix, $fields_values)
- {
- $field_options = Array (
- 'type' => 'string',
- 'formatter' => 'kPictureFormatter',
-// 'skip_empty' => 1,
- 'max_len' => 240,
- 'default' => '',
- 'not_null' => 1,
- 'include_path' => 1,
- 'allowed_types' => Array ('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif', 'image/bmp'),
- 'error_msgs' => Array (
- 'bad_file_format' => '!la_error_InvalidFileFormat!',
- 'bad_file_size' => '!la_error_FileTooLarge!',
- 'cant_save_file' => '!la_error_cant_save_file!'
- ),
- );
-
- $fields = $this->Application->getUnitOption($prefix, 'Fields');
- $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields');
-
- $image_count = 0;
- foreach ($fields_values as $field_name => $field_value) {
- if (preg_match('/^(Image[\d]+|PrimaryImage)$/', $field_name)) {
- $fields[$field_name] = $field_options;
- $virtual_fields[$field_name] = $field_options;
- $virtual_fields['Delete'.$field_name] = Array ('type' => 'int', 'not_null' => 1, 'default' => 0);
- $image_count++;
- }
- }
-
- if (!$image_count) {
- // no images found in POST -> create default image fields
- $image_names = Array ('PrimaryImage' => '');
- $image_count = $this->Application->ConfigValue($prefix.'_MaxImageCount');
-
- $created_count = 1;
- while ($created_count < $image_count) {
- $image_names['Image'.$created_count] = '';
- $created_count++;
- }
-
- $this->createImageFields($prefix, $image_names);
- return ;
- }
-
- $this->Application->setUnitOption($prefix, 'ImageCount', $image_count);
- $this->Application->setUnitOption($prefix, 'Fields', $fields);
- $this->Application->setUnitOption($prefix, 'VirtualFields', $virtual_fields);
- }
-
- /**
* Puts existing item images (from subitem) to virtual fields (in main item)
*
* @param kCatDBItem $object
@@ -364,23 +290,6 @@
$i++;
}
}
-
- /**
- * Preserves cloned item images to be rewrited with original item images
- *
- * @param Array $field_values
- */
- function PreserveItemImages(&$field_values)
- {
- foreach ($field_values as $field_name => $field_value) {
- if (!is_array($field_value)) continue;
-
- if (isset($field_value['upload']) && ($field_value['error'] == UPLOAD_ERR_NO_FILE)) {
- // this is upload field, but nothing was uploaded this time
- unset($field_values[$field_name]);
- }
- }
- }
}
?>
\ No newline at end of file
Index: branches/RC/kernel/units/files/files_config.php
===================================================================
diff -u -r9581 -r9598
--- branches/RC/kernel/units/files/files_config.php (.../files_config.php) (revision 9581)
+++ branches/RC/kernel/units/files/files_config.php (.../files_config.php) (revision 9598)
@@ -63,7 +63,7 @@
'not_null' => 1, 'required' => 1, 'default' => ''
),
'Size' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
- 'Status' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Enabled', 0 => 'la_Disabled'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 0),
+ 'Status' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Enabled', 0 => 'la_Disabled'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 1),
'IsPrimary' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'Priority' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'CreatedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'not_null' => 1, 'default' => '#NOW#'),
Index: branches/RC/core/units/general/cat_event_handler.php
===================================================================
diff -u -r9398 -r9598
--- branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 9398)
+++ branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 9598)
@@ -13,14 +13,16 @@
{
parent::mapPermissions();
$permissions = Array(
- 'OnExport' => Array('self' => 'view|advanced:export'),
- 'OnExportBegin' => Array('self' => 'view|advanced:export'),
- 'OnSaveSettings' => Array('self' => 'add|edit|advanced:import'),
- 'OnBeforeDeleteOriginal' => Array('self' => 'edit|advanced:approve'),
+ 'OnExport' => Array('self' => 'view|advanced:export'),
+ 'OnExportBegin' => Array('self' => 'view|advanced:export'),
+ 'OnSaveSettings' => Array('self' => 'add|edit|advanced:import'),
+ 'OnBeforeDeleteOriginal' => Array('self' => 'edit|advanced:approve'),
- 'OnCancelAction' => Array('self' => true),
- );
+ 'OnDownloadFile' => Array('self' => 'view'),
+ 'OnCancelAction' => Array('self' => true),
+ );
+
$this->permMapping = array_merge($this->permMapping, $permissions);
}
@@ -717,6 +719,12 @@
$image_helper->LoadItemImages($object);
+ // linking existing files for item with virtual fields
+ $file_helper =& $this->Application->recallObject('FileHelper');
+ /* @var $file_helper FileHelper */
+
+ $file_helper->LoadItemFiles($object);
+
// set item's additional categories to virtual field (used in editing)
$item_categories = $this->getItemCategories($object->GetDBField('ResourceId'));
$object->SetDBField('MoreCategories', $item_categories ? '|'.implode('|', $item_categories).'|' : '');
@@ -740,6 +748,12 @@
// process image upload in virtual fields
$image_helper->SaveItemImages($object);
+ $file_helper =& $this->Application->recallObject('FileHelper');
+ /* @var $file_helper FileHelper */
+
+ // process file upload in virtual fields
+ $file_helper->SaveItemFiles($object);
+
if ($event->Special != '-item') {
// don't touch categories during cloning
$this->processAdditionalCategories($object, 'update');
@@ -768,6 +782,12 @@
// process image upload in virtual fields
$image_helper->SaveItemImages($object);
+ $file_helper =& $this->Application->recallObject('FileHelper');
+ /* @var $file_helper FileHelper */
+
+ // process file upload in virtual fields
+ $file_helper->SaveItemFiles($object);
+
if ($event->Special != '-item') {
// don't touch categories during cloning
$this->processAdditionalCategories($object, 'create');
@@ -2027,8 +2047,8 @@
$owner_field = $this->getOwnerField($event->Prefix);
- $image_helper =& $this->Application->recallObject('ImageHelper');
- /* @var $image_helper ImageHelper */
+ $file_helper =& $this->Application->recallObject('FileHelper');
+ /* @var $file_helper FileHelper */
foreach ($items_info as $id => $field_values) {
$object->Load($id);
@@ -2038,7 +2058,7 @@
// pending editing enabled + not pending copy -> get/create pending copy & save changes to it
$original_id = $object->GetID();
$original_resource_id = $object->GetDBField('ResourceId');
- $image_helper->PreserveItemImages($field_values);
+ $file_helper->PreserveItemFiles($field_values);
$object->Load($original_id, 'OrgId');
if (!$object->isLoaded()) {
@@ -2283,12 +2303,40 @@
*/
function OnAfterConfigRead(&$event)
{
- $image_helper =& $this->Application->recallObject('ImageHelper');
- /* @var $image_helper ImageHelper */
+ $file_helper =& $this->Application->recallObject('FileHelper');
+ /* @var $file_helper FileHelper */
- $image_helper->createItemImages($event->Prefix);
+ $file_helper->createItemFiles($event->Prefix, true); // create image fields
+ $file_helper->createItemFiles($event->Prefix, false); // create file fields
}
+ /**
+ * Returns file contents associated with item
+ *
+ * @param kEvent $event
+ */
+ function OnDownloadFile(&$event)
+ {
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $event->status = erSTOP;
+
+ $field = $this->Application->GetVar('field');
+ if (!preg_match('/^File([\d]+)/', $field)) {
+ return ;
+ }
+
+ $filename = $object->GetField($field, 'full_path');
+
+ $content_type = function_exists('mime_content_type') ? mime_content_type($filename) : 'application/octet-stream';
+
+ header('Content-type: '.$content_type);
+ header('Content-Disposition: attachment; filename="'.basename($filename).'"');
+ header('Content-Length: '.filesize($filename));
+ readfile($filename);
+ flush();
+ }
}
?>
\ No newline at end of file
Index: branches/RC/kernel/units/helpers/file_helper.php
===================================================================
diff -u
--- branches/RC/kernel/units/helpers/file_helper.php (revision 0)
+++ branches/RC/kernel/units/helpers/file_helper.php (revision 9598)
@@ -0,0 +1,188 @@
+Application->ConfigValue($object->Prefix.'_MaxImageCount'); // file count equals to image count (temporary measure)
+
+ $sql = 'SELECT *
+ FROM '.TABLE_PREFIX.'ItemFiles
+ WHERE ResourceId = '.$object->GetDBField('ResourceId').'
+ ORDER BY FileId ASC
+ LIMIT 0, '.(int)$max_file_count;
+ $item_files = $this->Conn->Query($sql);
+
+ $file_counter = 1;
+ foreach ($item_files as $item_file) {
+ $file_path = $item_file['FilePath'];
+ $object->SetDBField('File'.$file_counter, $file_path);
+ $object->SetOriginalField('File'.$file_counter, $file_path);
+ $object->Fields['File'.$file_counter]['original_field'] = $item_file['FileName'];
+ $file_counter++;
+ }
+ }
+
+ /**
+ * Saves newly uploaded images to external image table
+ *
+ * @param kCatDBItem $object
+ */
+ function SaveItemFiles(&$object)
+ {
+ $table_name = $this->Application->getUnitOption('#file', 'TableName');
+ $max_file_count = $this->Application->getUnitOption($object->Prefix, 'FileCount'); // $this->Application->ConfigValue($object->Prefix.'_MaxImageCount');
+
+ $i = 0;
+ while ($i < $max_file_count) {
+ $field = 'File'.($i + 1);
+ $field_options = $object->GetFieldOptions($field);
+
+ $file_path = $object->GetDBField($field);
+ if ($file_path) {
+ if (isset($field_options['original_field'])) {
+ $key_clause = 'FileName = '.$this->Conn->qstr($field_options['original_field']).' AND ResourceId = '.$object->GetDBField('ResourceId');
+
+ if ($object->GetDBField('Delete'.$field)) {
+ // if item was cloned, then new filename is in db (not in $image_src)
+ $sql = 'SELECT FilePath
+ FROM '.$table_name.'
+ WHERE '.$key_clause;
+ $file_path = $this->Conn->GetOne($sql);
+ if (@unlink(FULL_PATH.ITEM_FILES_PATH.$file_path)) {
+ $sql = 'DELETE FROM '.$table_name.'
+ WHERE '.$key_clause;
+ $this->Conn->Query($sql);
+ }
+ }
+ else {
+ // image record found -> update
+ $fields_hash = Array (
+ 'FilePath' => $file_path,
+ );
+
+ $this->Conn->doUpdate($fields_hash, $table_name, $key_clause);
+ }
+ }
+ else {
+ // image record not found -> create
+ $fields_hash = Array (
+ 'ResourceId' => $object->GetDBField('ResourceId'),
+ 'FileName' => $field,
+ 'Enabled' => STATUS_ACTIVE,
+ 'FilePath' => $file_path,
+ );
+
+ $this->Conn->doInsert($fields_hash, $table_name);
+ $field_options['original_field'] = $field;
+ $object->SetFieldOptions($field, $field_options);
+ }
+ }
+ $i++;
+ }
+ }
+
+ /**
+ * Preserves cloned item images/files to be rewrited with original item images/files
+ *
+ * @param Array $field_values
+ */
+ function PreserveItemFiles(&$field_values)
+ {
+ foreach ($field_values as $field_name => $field_value) {
+ if (!is_array($field_value)) continue;
+
+ if (isset($field_value['upload']) && ($field_value['error'] == UPLOAD_ERR_NO_FILE)) {
+ // this is upload field, but nothing was uploaded this time
+ unset($field_values[$field_name]);
+ }
+ }
+ }
+
+ /**
+ * Determines what image/file fields should be created (from post or just dummy fields for 1st upload)
+ *
+ * @param string $prefix
+ * @param bool $is_image
+ */
+ function createItemFiles($prefix, $is_image = false)
+ {
+ $items_info = $this->Application->GetVar($prefix);
+ if ($items_info) {
+ list ($id, $fields_values) = each($items_info);
+ $this->createUploadFields($prefix, $fields_values, $is_image);
+ }
+ else {
+ $this->createUploadFields($prefix, Array(), $is_image);
+ }
+ }
+
+ /**
+ * Dynamically creates virtual fields for item for each image/file field in submit
+ *
+ * @param string $prefix
+ * @param Array $fields_values
+ * @param bool $is_image
+ */
+ function createUploadFields($prefix, $fields_values, $is_image = false)
+ {
+ $field_options = Array (
+ 'type' => 'string',
+ 'max_len' => 240,
+ 'default' => '',
+ 'not_null' => 1,
+ );
+
+ if ($is_image) {
+ $field_options['formatter'] = 'kPictureFormatter';
+ $field_options['include_path'] = 1;
+ $fields_values['allowed_types'] = Array ('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif', 'image/bmp');
+ $field_prefix = 'Image';
+ }
+ else {
+ $field_options['formatter'] = 'kUploadFormatter';
+ $field_options['upload_dir'] = ITEM_FILES_PATH;
+ $fields_values['allowed_types'] = Array ('application/pdf', 'application/msexcel', 'application/msword', 'application/mspowerpoint');
+ $field_prefix = 'File';
+ }
+
+ $fields = $this->Application->getUnitOption($prefix, 'Fields');
+ $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields');
+
+ $image_count = 0;
+ foreach ($fields_values as $field_name => $field_value) {
+ if (preg_match('/^('.$field_prefix.'[\d]+|Primary'.$field_prefix.')$/', $field_name)) {
+ $fields[$field_name] = $field_options;
+ $virtual_fields[$field_name] = $field_options;
+ $virtual_fields['Delete'.$field_name] = Array ('type' => 'int', 'not_null' => 1, 'default' => 0);
+ $image_count++;
+ }
+ }
+
+ if (!$image_count) {
+ // no images found in POST -> create default image fields
+ $image_names = Array ('Primary'.$field_prefix => '');
+ $image_count = $this->Application->ConfigValue($prefix.'_MaxImageCount');
+
+ $created_count = 1;
+ while ($created_count < $image_count) {
+ $image_names[$field_prefix.$created_count] = '';
+ $created_count++;
+ }
+
+ $this->createUploadFields($prefix, $image_names, $is_image);
+ return ;
+ }
+
+ $this->Application->setUnitOption($prefix, $field_prefix.'Count', $image_count);
+ $this->Application->setUnitOption($prefix, 'Fields', $fields);
+ $this->Application->setUnitOption($prefix, 'VirtualFields', $virtual_fields);
+ }
+ }
+
+?>
\ No newline at end of file
Index: branches/RC/kernel/units/helpers/helpers_config.php
===================================================================
diff -u -r8929 -r9598
--- branches/RC/kernel/units/helpers/helpers_config.php (.../helpers_config.php) (revision 8929)
+++ branches/RC/kernel/units/helpers/helpers_config.php (.../helpers_config.php) (revision 9598)
@@ -6,6 +6,7 @@
'RegisterClasses' => Array (
Array('pseudo' => 'SpamHelper', 'class' => 'SpamHelper','file' => 'spam_helper.php', 'build_event' => '', 'require_classes' => Array('kHelper')),
+ Array('pseudo' => 'FileHelper', 'class' => 'FileHelper','file' => 'file_helper.php', 'build_event' => '', 'require_classes' => Array('kHelper')),
),
);
Index: branches/RC/admin/install/upgrades/inportal_upgrade_v4.2.1.sql
===================================================================
diff -u -r9581 -r9598
--- branches/RC/admin/install/upgrades/inportal_upgrade_v4.2.1.sql (.../inportal_upgrade_v4.2.1.sql) (revision 9581)
+++ branches/RC/admin/install/upgrades/inportal_upgrade_v4.2.1.sql (.../inportal_upgrade_v4.2.1.sql) (revision 9598)
@@ -17,7 +17,7 @@
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'Catalog_PreselectModuleTab', 1, 'In-Portal', 'in-portal:configure_categories');
INSERT INTO ConfigurationAdmin VALUES ('Catalog_PreselectModuleTab', 'la_Text_General', 'la_config_CatalogPreselectModuleTab', 'checkbox', NULL, NULL, 10.09, 0, 1);
-CREATE TABLE ItemFiles (FileId int(11) NOT NULL auto_increment, ResourceId int(11) unsigned NOT NULL default '0', FileName varchar(255) NOT NULL default '', FilePath varchar(255) NOT NULL default '', Size int(11) NOT NULL default '0', `Status` tinyint(4) NOT NULL default '0', IsPrimary tinyint(4) NOT NULL default '0', Priority smallint(6) NOT NULL default '0', CreatedOn int(11) unsigned NOT NULL default '0', CreatedById int(11) NOT NULL default '-1', MimeType varchar(255) NOT NULL default '', PRIMARY KEY (FileId), KEY ResourceId (ResourceId));
+CREATE TABLE ItemFiles (FileId int(11) NOT NULL auto_increment, ResourceId int(11) unsigned NOT NULL default '0', FileName varchar(255) NOT NULL default '', FilePath varchar(255) NOT NULL default '', Size int(11) NOT NULL default '0', `Status` tinyint(4) NOT NULL default '0', CreatedOn int(11) unsigned NOT NULL default '0', CreatedById int(11) NOT NULL default '-1', MimeType varchar(255) NOT NULL default '', PRIMARY KEY (FileId), KEY ResourceId (ResourceId));
UPDATE Modules SET Version = '4.2.1' WHERE Name = 'Core';
UPDATE Modules SET Version = '4.2.1' WHERE Name = 'In-Portal';
\ No newline at end of file
Index: branches/RC/kernel/units/files/file_eh.php
===================================================================
diff -u -r9581 -r9598
--- branches/RC/kernel/units/files/file_eh.php (.../file_eh.php) (revision 9581)
+++ branches/RC/kernel/units/files/file_eh.php (.../file_eh.php) (revision 9598)
@@ -23,17 +23,6 @@
*/
function OnBeforeItemCreate(&$event)
{
- parent::OnBeforeItemCreate($event);
-
- $object =& $event->getObject();
-
- $this->resetPrimary($object);
-
- if (!$this->primaryFileFound($object)) {
- $object->SetDBField('IsPrimary', 1);
- $object->SetDBField('Status', STATUS_ACTIVE);
- }
-
$object->SetDBField('CreatedById', $this->Application->RecallVar('user_id'));
}
@@ -46,99 +35,11 @@
{
$object =& $event->getObject();
- $this->resetPrimary($object);
-
if (!$object->GetDBField('FileName')) {
$object->SetDBField('FileName', basename($object->GetDBField('FilePath')));
}
}
- /**
- * Checks for primary file along all files with same main item
- *
- * @param kDBItem $object
- * @return int
- */
- function primaryFileFound(&$object)
- {
- $sql = 'SELECT '.$object->IDField.'
- FROM '.$object->TableName.'
- WHERE (IsPrimary = 1) AND ('.$this->getParentClause($object).')';
- return $this->Conn->GetOne($sql);
- }
-
- /**
- * Resets primary mark from all item files
- *
- * @param kDBItem $object
- */
- function resetPrimary(&$object)
- {
- if (!$object->GetDBField('IsPrimary')) {
- return ;
- }
-
- $sql = 'UPDATE '.$object->TableName.'
- SET IsPrimary = 0
- WHERE '.$this->getParentClause($object);
- $this->Conn->Query($sql);
-
- $object->SetDBField('Status', STATUS_ACTIVE);
- }
-
- /**
- * Makes selected file primary
- *
- * @param kEvent $event
- */
- function OnSetPrimary(&$event)
- {
- $ids = $this->StoreSelectedIDs($event);
- if (!$ids) {
- return ;
- }
-
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $object->Load( array_shift($ids) );
-
- $object->SetDBField('IsPrimary', 1);
- $object->Update();
-
- $this->clearSelectedIDs($event);
- }
-
- /**
- * Don't allow to delete other user's messages
- *
- * @param kEvent $event
- */
- function customProcessing(&$event, $type)
- {
- parent::customProcessing($event, $type);
- if ($event->Name == 'OnMassDelete' && $type == 'before') {
- $ids = $event->getEventParam('ids');
- if ($ids) {
- $object =& $event->getObject();
- /* @var $object kDBItem */
-
- $primary_file_id = $this->primaryFileFound($object);
- if ($primary_file_id && ($primary_index = array_search($primary_file_id, $ids))) {
- $sql = 'SELECT COUNT(*)
- FROM '.$object->TableName.'
- WHERE (IsPrimary = 0) AND ('.$this->getParentClause($object).')';
- $non_primary_found = $this->Conn->Query($sql);
-
- if ($non_primary_found) {
- // non-primary files found for same main item -> don't delete primary file until all non-primary files are deleted
- unset($ids[$primary_index]);
- }
- }
-
- $event->setEventParam('ids', $ids);
- }
- }
- }
-
function SetCustomQuery(&$event)
{
parent::SetCustomQuery($event);
@@ -149,18 +50,6 @@
$object->addFilter('active_filter', '%1$s.Status = '.STATUS_ACTIVE);
}
}
-
- /**
- * Returns sql clause, that links file to it's parent item
- *
- * @param kDBItem $object
- * @return string
- */
- function getParentClause(&$object)
- {
- $parent_info = $object->getLinkedInfo($object->Special);
- return $parent_info['ForeignKey'].' = '.$parent_info['ParentId'];
- }
}
?>
\ No newline at end of file
|