ElkArte Community

Elk Development => Bug Reports => Topic started by: badmonkey on February 17, 2019, 03:40:19 pm

Title: Attachment Directory management error
Post by: badmonkey on February 17, 2019, 03:40:19 pm
php7.3, nginx 1.15.8, mariadb 10.3. Fresh 1.1.5 install. When attempting to change Choose the method for the management of the attachment directories to Auto Subdivide by months and years and checking box Create new directories within a base directory, there is an error "in_array() expects parameter 2 to be array, string given". Anyone know a fix? Thanks!

Edit: the offending feature seems to be checking the Auto Subdivide. Choosing the option fails to create a subdirectory, and naturally attachment uploads fail. 
Title: Re: Attachment Directory management error
Post by: Spuds on February 18, 2019, 11:36:08 am
Did it indicate which line the error is on? 

Title: Re: Attachment Directory management error
Post by: badmonkey on February 18, 2019, 04:59:24 pm
Quote from: Spuds – Did it indicate which line the error is on?
 
 Sure did! 


Code: [Select]
ManageAttachments.controller.php

Line: 218
Title: Re: Attachment Directory management error
Post by: Spuds on February 18, 2019, 06:35:31 pm
Hummm .... try adding the following line just above that line ( in ManaageAttachments.controller.php )
Code: [Select]
					$modSettings['attachmentUploadDir'] = !empty($modSettings['attachmentUploadDir']) ?: array();
and lets see what happens
Title: Re: Attachment Directory management error
Post by: badmonkey on February 18, 2019, 09:09:45 pm
Quote from: Spuds – Hummm .... try adding the following line just above that line ( in ManaageAttachments.controller.php )
Code: [Select]
					$modSettings['attachmentUploadDir'] = !empty($modSettings['attachmentUploadDir']) ?: array();
and lets see what happens
 
 Well, it must be progress!  ;D Now the error is:


Code: [Select]
Warning: in_array() expects parameter 2 to be array, bool given
Title: Re: Attachment Directory management error
Post by: Spuds on February 18, 2019, 10:12:13 pm
Humm .... this is why @emanuele is updating this code for 2.0 :D

Just for a test, try using
Code: [Select]
					if (empty($modSettings['attachmentUploadDir']))
{
$modSettings['attachmentUploadDir'] = array();
}
else
{
$test = @Util::unserialize($modSettings['attachmentUploadDir']);
if ($test === false)
{
$modSettings['attachmentUploadDir'] = array($modSettings['attachmentUploadDir']);
}
else
{
$modSettings['attachmentUploadDir'] = $test;
}
}
instead of the other single line I gave you.
Title: Re: Attachment Directory management error
Post by: emanuele on February 19, 2019, 02:24:29 am
Maybe...
Line 190:
Code: [Select]
if (isset($this->_req->post->attachmentUploadDir))
to:
Code: [Select]
			if (isset($this->_req->post->attachmentUploadDir) ||
!empty($this->_req->post->use_subdirectories_for_attachments))
Title: Re: Attachment Directory management error
Post by: badmonkey on February 19, 2019, 08:12:52 am
Quote from: emanuele – Maybe...
Line 190:
Code: [Select]
if (isset($this->_req->post->attachmentUploadDir))
to:
Code: [Select]
			if (isset($this->_req->post->attachmentUploadDir) ||
!empty($this->_req->post->use_subdirectories_for_attachments))
 
 Tried this. There was no error managing the settings. However, setting it to Auto subdivided by month and year resulted in no directory created and, of course, inability to upload.
Title: Re: Attachment Directory management error
Post by: badmonkey on February 20, 2019, 08:20:54 am
Quote from: Spuds – Humm .... this is why @emanuele is updating this code for 2.0 :D

Just for a test, try using
Code: [Select]
					if (empty($modSettings['attachmentUploadDir']))
{
$modSettings['attachmentUploadDir'] = array();
}
else
{
$test = @Util::unserialize($modSettings['attachmentUploadDir']);
if ($test === false)
{
$modSettings['attachmentUploadDir'] = array($modSettings['attachmentUploadDir']);
}
else
{
$modSettings['attachmentUploadDir'] = $test;
}
}
instead of the other single line I gave you.
 
 
This code also removes the original error, and results in no directory creation (which you probably expected). 
Title: Re: Attachment Directory management error
Post by: Spuds on February 20, 2019, 06:47:12 pm
Yeah so the code is a bit broken ....  but I think you know that  O:-)

FYI what I personally do is create directories for each year, and I manually create them :(  I don't really see the need for monthly separation unless you were on a site that created an enormous number of attachments.   I break it down by year just to simplify my backup scripts.

In 2.0 the plan was to simply that code, it simply allows to many options which causes complications for everyone.

Title: Re: Attachment Directory management error
Post by: badmonkey on February 20, 2019, 08:21:10 pm
Quote from: Spuds – Yeah so the code is a bit broken ....  but I think you know that  O:-)
 
 So it is. It's difficult casting stones unless one happens to be a professional coder, in which case said individual would write their own stuff. Suffice that to say the work you guys do is much appreciated! Elk is awesome software, even better is question response. 

Quote from: Spuds – FYI what I personally do is create directories for each year, and I manually create them :(  I don't really see the need for monthly separation unless you were on a site that created an enormous number of attachments.  I break it down by year just to simplify my backup scripts.

In 2.0 the plan was to simply that code, it simply allows to many options which causes complications for everyone.
 
 My sites are probably more image oriented than most. Still, "enormous" wouldn't be a great numeric descriptor regarding them. You have a good plan there. It would be cool if the software truly auto sorted even by year. But it is no biggie if it doesn't.

Thanks spuds!
Title: Re: Attachment Directory management error
Post by: emanuele on February 21, 2019, 04:52:25 am
I think the most common limit to avoid is the usually 10k files per directory that is enforced for ftp in certain configurations (i.e. the ftp returns only the first 10k files). Though this limit is not always present, so it's a kind of case-by-case.
Apart from that, it could be wise to avoid to have more than 10k files in a directory just to remain sane.
Title: Re: Attachment Directory management error
Post by: badmonkey on February 21, 2019, 09:35:32 am
Quote from: emanuele – I think the most common limit to avoid is the usually 10k files per directory that is enforced for ftp in certain configurations (i.e. the ftp returns only the first 10k files). Though this limit is not always present, so it's a kind of case-by-case.
Apart from that, it could be wise to avoid to have more than 10k files in a directory just to remain sane.
 
 That said, is there a way to move files from a specific timeframe to a different directory? Or move specific files?
Title: Re: Attachment Directory management error
Post by: ahrasis on March 27, 2019, 10:00:39 am
I don't think this one is tracked yet for 1.1.6. Not sure about 2.0.
Title: Re: Attachment Directory management error
Post by: Spuds on April 02, 2019, 11:27:25 am
Tracked: https://github.com/elkarte/Elkarte/issues/3298