XF 1.1 Server error opening PC after remove attachment template edit

Andy.N

Well-known member
I have used a template modification here that allow people to attach files to Personal Conversation. It appears that thread here has been removed
http://xenforo.com/community/threads/conversation-attachments.14663/

This addon requires several manual templates edit: conversation_reply, conversation_message_edit, conversation_add, conversation_message

After upgrade to 1.1, I revert these templates thinking the I no longer need this because 1.1 comes with PC attachment.

Now, when I go to my inbox and go to any of my PC, it will display this error.

Server Error

Undefined index: attach_count
  1. XenForo_Application::handlePhpError() in XenForo/Model/Conversation.php at line 1294
  2. XenForo_Model_Conversation->getAndMergeAttachmentsIntoConversationMessages() in XenForo/ControllerPublic/Conversation.php at line 190
  3. XenForo_ControllerPublic_Conversation->actionView() in XenForo/FrontController.php at line 310
  4. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
  5. XenForo_FrontController->run() in /var/data/public/forum/index.php at line 13
 
I have backed out my site to v1.0 (stable), will leave the 1.1 upgrade until the custom sytles are working with 1.1

Jake, I will remember to uninstall the attachment mod beforehand, so it should be ok when I do take the plunge :)
thanks for your help
 
To prevent any conflicts and remove the existing attachments, uninstall it as-is before upgrading to 1.1.

To prevent any conflicts and keep the existing attachments, replace /library/ConversationAttachments/Install.php with the attached version, and uninstall it before upgrading to 1.1.

If you've already upgraded and then uninstalled and are now receiving errors, you will have to run Jake's queries from the 1st page. If not run as soon as possible after uninstalling you risk losing existing attachments.

My sincere apologies for the trouble.
 

Attachments

What if you have no back-up?

Then we have to deal with the damage to your 1.1 database. Based on the uninstall code for the addon Andy sent me, these queries should fix your 1.1 database and preserve old attachments:

Code:
ALTER TABLE xf_conversation_message
ADD attach_count SMALLINT UNSIGNED NOT NULL DEFAULT 0;

UPDATE xf_attachment
SET unassociated = 0
WHERE content_type = 'conversation_message';

UPDATE xf_conversation_message AS cm
SET cm.attach_count = (
	SELECT COUNT(*)
	FROM xf_attachment AS a
	WHERE a.content_id = cm.message_id
	AND a.content_type = 'conversation_message'
);

INSERT INTO xf_content_type
	(content_type, addon_id, fields)
VALUES
	('conversation_message', 'XenForo', BINARY 'a:2:{s:24:"attachment_handler_class";s:45:"XenForo_AttachmentHandler_ConversationMessage";s:20:"report_handler_class";s:41:"XenForo_ReportHandler_ConversationMessage";}');

INSERT INTO xf_content_type_field
	(content_type, field_name, field_value)
VALUES
	('conversation_message', 'report_handler_class', 'XenForo_ReportHandler_ConversationMessage'),
	('conversation_message', 'attachment_handler_class', 'XenForo_AttachmentHandler_ConversationMessage');

Let me know if it works.
 
Then we have to deal with the damage to your 1.1 database. Based on the uninstall code for the addon Andy sent me, these queries should fix your 1.1 database and preserve old attachments:

Code:
ALTER TABLE xf_conversation_message
ADD attach_count SMALLINT UNSIGNED NOT NULL DEFAULT 0;

UPDATE xf_attachment
SET unassociated = 0
WHERE content_type = 'conversation_message';

UPDATE xf_conversation_message AS cm
SET cm.attach_count = (
SELECT COUNT(*)
FROM xf_attachment AS a
WHERE a.content_id = cm.message_id
AND a.content_type = 'conversation_message'
);

INSERT INTO xf_content_type
(content_type, addon_id, fields)
VALUES
('conversation_message', 'XenForo', BINARY 'a:2:{s:24:"attachment_handler_class";s:45:"XenForo_AttachmentHandler_ConversationMessage";s:20:"report_handler_class";s:41:"XenForo_ReportHandler_ConversationMessage";}');

INSERT INTO xf_content_type_field
(content_type, field_name, field_value)
VALUES
('conversation_message', 'report_handler_class', 'XenForo_ReportHandler_ConversationMessage'),
('conversation_message', 'attachment_handler_class', 'XenForo_AttachmentHandler_ConversationMessage');

Let me know if it works.
Thanks but where do I do this at?
 
Then we have to deal with the damage to your 1.1 database. Based on the uninstall code for the addon Andy sent me, these queries should fix your 1.1 database and preserve old attachments:

Code:
ALTER TABLE xf_conversation_message
ADD attach_count SMALLINT UNSIGNED NOT NULL DEFAULT 0;
 
UPDATE xf_attachment
SET unassociated = 0
WHERE content_type = 'conversation_message';
 
UPDATE xf_conversation_message AS cm
SET cm.attach_count = (
SELECT COUNT(*)
FROM xf_attachment AS a
WHERE a.content_id = cm.message_id
AND a.content_type = 'conversation_message'
);
 
INSERT INTO xf_content_type
(content_type, addon_id, fields)
VALUES
('conversation_message', 'XenForo', BINARY 'a:2:{s:24:"attachment_handler_class";s:45:"XenForo_AttachmentHandler_ConversationMessage";s:20:"report_handler_class";s:41:"XenForo_ReportHandler_ConversationMessage";}');
 
INSERT INTO xf_content_type_field
(content_type, field_name, field_value)
VALUES
('conversation_message', 'report_handler_class', 'XenForo_ReportHandler_ConversationMessage'),
('conversation_message', 'attachment_handler_class', 'XenForo_AttachmentHandler_ConversationMessage');

Let me know if it works.

Thank you Jake, worked perfectly :)
 
Top Bottom