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
 
xf_conversation_message.attach_count was added in 1.1 yet it appears to be missing on your forum.

I am not familiar with that modification. Was it an addon involving database changes? Did you perhaps uninstall it and thereby remove that column?
 
xf_conversation_message.attach_count was added in 1.1 yet it appears to be missing on your forum.

I am not familiar with that modification. Was it an addon involving database changes? Did you perhaps uninstall it and thereby remove that column?
Jake
I believe the addon will add another column to the xf_messages table.
I disable it prior to the upgrade and then revert the templates.

What would be the correct approach?
 
Reverting the manual template edits is fine. That shouldn't cause any problems.

But if the addon added a column to the database which was later added by a new version of XenForo then there is a potential conflict. In that event it would be best to completely uninstall the addon prior to the upgrade (instead of just disabling it). But that might cause you to lose previous conversation attachments. It may be possible to migrate your old conversation attachments into the new system with some extra effort.

I wish that thread link still worked. I would like to download and test that addon to see exactly what is going on.
 
Reverting the manual template edits is fine. That shouldn't cause any problems.

But if the addon added a column to the database which was later added by a new version of XenForo then there is a potential conflict. In that event it would be best to completely uninstall the addon prior to the upgrade (instead of just disabling it). But that might cause you to lose previous conversation attachments. It may be possible to migrate your old conversation attachments into the new system with some extra effort.

I wish that thread link still worked. I would like to download and test that addon to see exactly what is going on.
I still have the addon zip file as well as template edits that you can track back all the changes. How do you like to get it. I couldn't attach the zip file here.
I'm glad i'm testing this on a test board. Phew ;)
 
I examined the addon you sent me. It is as I thought. The install code adds that field and the uninstall code removes it. So if you uninstall this addon after upgrading to 1.1 then you will lose that field resulting in the error you posted.

If you don't care about preserving old conversation attachments then you can just uninstall the addon before upgrading.

If you want to preserve the attachments then I still recommend that you uninstall the addon before upgrading. Then after the upgrade you can reassociate the attachments by querying the database. I think this process will work:

1) Uninstall the addon.
2) Upgrade to 1.1
3) Run these queries to reassociate the attachments and rebuild the counts:

Code:
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'
);

This should result in the old attachments being preserved. I examined the addon and found that it uses the same content_type that 1.1 now uses. And I can see that the uninstall code leaves the attachments in the database when you uninstall the addon - it just flags them as unassociated. The attachments still have their original content_ids and content_types which are valid in 1.1. So you just need to flag them as associated after you upgrade. The only other consideration is the content_type definition which should be taken care of by uninstalling the addon and then upgrading to 1.1.

Try it out. Let me know if it works.
 
3) Run these queries to reassociate the attachments and rebuild the counts:

Code:
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'
);
Jake,
Do you know how I can run those query from SSH instead of login phpmyAdmin?
 
Use this shell command to login to mysql. Replace the CAPITALIZED parts with your mysql credentials (from the library/config.php file):

Code:
mysql -uUSERNAME -pPASSWORD DBNAME

That will take you to the mysql prompt where you can paste the above queries.
 
I was able to retain the old attachments in PC when I did a test upgrade for 1.1b1 but I spent the last hour or so trying to figure out why the attachments disappear when I did a 1.1b2 upgrade.
I follow the exact same step. Uninstall, upgrade, run the queries, revert templates.
 
Something is very wrong. When I run those 2 queries, it returns 160+ rows effects, now when I run it after the 1.1b2 upgrade, both return 0 rows.

In the Attachments Browsers, it shows only 5 attachments in PC that was upload yesterday and I know for a fact that there are much much more.
 
Maybe there are something changed in 1.1b2 that no longer works as we did in 1.1b1?
For the time being, I will revert it back to 1.0.4 for further inspection.
 
I don't see any changes in the beta2 upgrade that would affect this.

Note that those queries are only needed one time when making the initial upgrade to 1.1. For subsequent upgrades (such as beta1 to beta2) you don't need to run those queries again. It won't hurt anything if you run them again, but they won't do anything (0 row returned). And of course the addon was already uninstalled during the initial upgrade to 1.1 so you don't need to uninstall that again. It's just a regular upgrade.
 
I don't see any changes in the beta2 upgrade that would affect this.

Note that those queries are only needed one time when making the initial upgrade to 1.1. For subsequent upgrades (such as beta1 to beta2) you don't need to run those queries again. It won't hurt anything if you run them again, but they won't do anything (0 row returned). And of course the addon was already uninstalled during the initial upgrade to 1.1 so you don't need to uninstall that again. It's just a regular upgrade.
Thanks Jake
Just to be clear. I have tested the procedure on a 1.0.4 backup to 1.1b1
Today, I upgraded the 1.0.4 live board to 1.1b2 directly without ever upgrading to b1 before.

If you like a challenge (I read your interview where you love corrupt installation, etc), you'll have a PM ;)
 
Sure. Send me a PM with FTP / admin logins and I will take a look.

You said some of your conversation attachments have disappeared. It would help to have the 1.0.4 and 1.1.0 dbs both up and running via phpmyadmin so I can compare the two, see the before and after.
 
All sorted now, Jake.
I have to upgrade to beta 1 first, make sure all is working and then upgrade to b2.
It looks like going from 1.0.4 to b2 will not work.
 
I am getting the same problem, I have removed the attachments upload mod, but now I get the following when trying to view personal conversations.

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 /home/www-data/ssl/index.php at line 13
I am not wanting to keep any of the old attachments from messages that used the old attachments mod.
Is there any way I can totally remove this mod or database entries and just use the personal messages from 1.1 beta2 ?
 
I am not wanting to keep any of the old attachments from messages that used the old attachments mod, is there any way I can totally remove this mod and get working personal messages again ?

Uninstall the addon before upgrading to 1.1. If you already upgraded then you need to revert to a backup from before the upgrade, uninstall the addon, then run the upgrade.
 
Top Bottom