Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FilesModel::findByPid() funktioniert nicht mit UUIDs #925

Closed
websolutions-hamburg opened this issue Jul 5, 2017 · 13 comments
Closed

FilesModel::findByPid() funktioniert nicht mit UUIDs #925

websolutions-hamburg opened this issue Jul 5, 2017 · 13 comments
Assignees
Labels
Milestone

Comments

@websolutions-hamburg
Copy link

Hallo,

die Funktion \FilesModel::findByPid() scheint noch nicht für UUIDs vorbereitet zu sein.

Funktionen wie \FilesModel::findById() bzw. deren Weiterleitung an die Funktion \FilesModel::findByUuid() haben eine spezielle Abfrage für UUIDs und eine passende Format Umwandlung mit Hilfe von \StringUtil::uuidToBin($strUuid).

Bei der Funktion \FilesModel::findByPid() werden die UUIDs jedoch nicht in ein Binary Format umgewandelt, sondern direkt an den SQL Select Befehl weitergegeben. Dadurch funktioniert dieser dann nicht richtig und liefert keine Ergebnis.

@fritzmg
Copy link
Contributor

fritzmg commented Jul 5, 2017

Would make sense, but what exactly is your use case though? Are you storing folder UUIDs as strings somewhere?

@leofeyer leofeyer added the bug label Jul 5, 2017
@leofeyer leofeyer added this to the 4.4.1 milestone Jul 5, 2017
@leofeyer leofeyer changed the title \FilesModel::findByPid() funktioniert nicht mit UUIDs FilesModel::findByPid() funktioniert nicht mit UUIDs Jul 5, 2017
@websolutions-hamburg
Copy link
Author

Not storing, but I select a folder with

'inputType' => 'fileTree',
'eval' => array(
    'fieldType' => 'radio',
    'mandatory' => false,
    'files' => false,
    'filesOnly' => false
)

and get the UUID from the folder. Later I will get all files from this folder. Maybe I can use \FilesModel::findMultipleFilesByFolder(). But for this I need 2 SQL select calls. The first to get the folder path from the UUID and the second to get the files.
With \FilesModel::findByPid() it will be only one select call. Or do I overlook something?

@fritzmg
Copy link
Contributor

fritzmg commented Jul 5, 2017

Post the complete DCA definition of your field.

@websolutions-hamburg
Copy link
Author

websolutions-hamburg commented Jul 5, 2017

I use the extension contao-rocksolid-custom-elements with this DCA:

'label' => array(
    'Hintergrundbilder',
    'Lädt die Hintergrundbilder'),
'types' => array('content'),
'contentCategory' => 'media',

'fields' => array(
    'images_folder' => array(
        'label' => array(
            'Ordner',
            'Wählen Sie den Ordner.'),
        'inputType' => 'fileTree',
        'eval' => array(
            'fieldType' => 'radio',
            'mandatory' => false,
            'files' => false,
            'filesOnly' => false
        )
    )
)

And in the config file of this custom element I get the UUID of the folder with $this->images_folder.

@fritzmg
Copy link
Contributor

fritzmg commented Jul 5, 2017

I use the extension contao-rocksolid-custom-elements with this DCA:

Ah, that's the problem then. Usually if you use the fileTree widget, your SQL field for storage would be blob or binary(16) - and the UUID will be saved in the binary format. However, with RSCE, the value is probably transformed by the extension from binary to string before being saved in rsce_data.

Nevertheless, as I said it would make sense to introduce a conversion like in findByUuid as well :) 👍

@leofeyer
Copy link
Member

leofeyer commented Jul 5, 2017

A method findByUuid() exists. I think @websolutions-hamburg needs a findByPid() with a built-in if (Validator::isUuid( check.

@leofeyer leofeyer added feature and removed bug labels Jul 5, 2017
@leofeyer leofeyer modified the milestones: 4.5.0, 4.4.1 Jul 5, 2017
@fritzmg
Copy link
Contributor

fritzmg commented Jul 5, 2017

Yes, that's what I meant.

@websolutions-hamburg
Copy link
Author

... with RSCE, the value is probably transformed by the extension from binary to string before being saved in rsce_data.

Ah ok. Good to know ;-)
Thanks for this information!

@leofeyer yes, that's right.

@leofeyer
Copy link
Member

Hm, I just wanted to implement the method, however, it does not really make sense, does it? tl_files.pid is always a UUID, so what exactly do you want the method to do?

@ausi
Copy link
Member

ausi commented Nov 21, 2017

so what exactly do you want the method to do?

Convert string UUIDs that get passed into the method to binary UUIDs?

@leofeyer
Copy link
Member

Like this?

public static function findByPid($intPid, array $arrOptions=array())
{
	$t = static::$strTable;

	// Convert UUIDs to binary
	if (\Validator::isStringUuid($intPid))
	{
		$intPid = \StringUtil::uuidToBin($intPid);
	}

	return static::findBy(array("$t.uuid=UNHEX(?)"), bin2hex($intPid), $arrOptions);
}

@ausi
Copy link
Member

ausi commented Nov 21, 2017

Yes 👍

@leofeyer leofeyer self-assigned this Nov 21, 2017
@leofeyer
Copy link
Member

Implemented in 9f5adad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants