ElkArte Community

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

Title: Attachment Directory management error
Post by: badmonkey on February 17, 2019, 09: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, 05:36:08 pm
Did it indicate which line the error is on? 

Title: Re: Attachment Directory management error
Post by: badmonkey on February 18, 2019, 10:59:24 pm
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 19, 2019, 12:35:31 am
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 19, 2019, 03:09:45 am
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 19, 2019, 04:12:13 am
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, 08: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, 02:12:52 pm
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, 02:20:54 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.
 
 
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 21, 2019, 12:47:12 am
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 21, 2019, 02:21:10 am
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. 

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, 10: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, 03:35:32 pm
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, 03:00:39 pm
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, 05:27:25 pm
Tracked: https://github.com/elkarte/Elkarte/issues/3298