@@ -207,6 +207,10 @@ public function __construct(FactoryInterface $factory, Connection $conn)
207
207
private function registerSqliteFunctions (PDOConnection $ sqliteConnection )
208
208
{
209
209
$ sqliteConnection ->sqliteCreateFunction ('EXTRACTVALUE ' , function ($ string , $ expression ) {
210
+ if (null === $ string ) {
211
+ return null ;
212
+ }
213
+
210
214
$ dom = new \DOMDocument ('1.0 ' , 'UTF-8 ' );
211
215
$ dom ->loadXML ($ string );
212
216
$ xpath = new \DOMXPath ($ dom );
@@ -571,10 +575,20 @@ public function copyNode($srcAbsPath, $dstAbsPath, $srcWorkspace = null)
571
575
foreach ($ stmt ->fetchAll (\PDO ::FETCH_ASSOC ) as $ row ) {
572
576
$ newPath = str_replace ($ srcAbsPath , $ dstAbsPath , $ row ['path ' ]);
573
577
574
- $ dom = new \DOMDocument ('1.0 ' , 'UTF-8 ' );
575
- $ dom ->loadXML ($ row ['props ' ]);
578
+ $ stringDom = new \DOMDocument ('1.0 ' , 'UTF-8 ' );
579
+ $ stringDom ->loadXML ($ row ['props ' ]);
580
+
581
+ $ numericalDom = null ;
576
582
577
- $ propsData = array ('dom ' => $ dom );
583
+ if ($ row ['numerical_props ' ]) {
584
+ $ numericalDom = new \DOMDocument ('1.0 ' , 'UTF-8 ' );
585
+ $ numericalDom ->loadXML ($ row ['numerical_props ' ]);
586
+ }
587
+
588
+ $ propsData = array (
589
+ 'stringDom ' => $ stringDom ,
590
+ 'numericalDom ' => $ numericalDom
591
+ );
578
592
// when copying a node, the copy is always a new node. set $isNewNode to true
579
593
$ newNodeId = $ this ->syncNode (null , $ newPath , $ row ['type ' ], true , array (), $ propsData );
580
594
@@ -646,25 +660,27 @@ private function syncNode($uuid, $path, $type, $isNewNode, $props = array(), $pr
646
660
647
661
$ qb = $ this ->conn ->createQueryBuilder ();
648
662
649
- $ qb ->select (':identifier, :type, :path, :local_name, :namespace, :parent, :workspace_name, :props, :depth, COALESCE(MAX(n.sort_order), 0) + 1 ' )
663
+ $ qb ->select (':identifier, :type, :path, :local_name, :namespace, :parent, :workspace_name, :props, :numerical_props, : depth, COALESCE(MAX(n.sort_order), 0) + 1 ' )
650
664
->from ('phpcr_nodes ' , 'n ' )
651
665
->where ('n.parent = :parent_a ' );
652
666
653
667
$ sql = $ qb ->getSql ();
654
668
655
669
try {
656
- $ insert = "INSERT INTO phpcr_nodes (identifier, type, path, local_name, namespace, parent, workspace_name, props, depth, sort_order) " . $ sql ;
657
- $ this ->conn ->executeUpdate ($ insert , array (
658
- 'identifier ' => $ uuid ,
659
- 'type ' => $ type ,
660
- 'path ' => $ path ,
661
- 'local_name ' => $ localName ,
662
- 'namespace ' => $ namespace ,
663
- 'parent ' => PathHelper::getParentPath ($ path ),
670
+ $ insert = "INSERT INTO phpcr_nodes (identifier, type, path, local_name, namespace, parent, workspace_name, props, numerical_props, depth, sort_order) " . $ sql ;
671
+
672
+ $ this ->conn ->executeUpdate ($ insert , $ data = array (
673
+ 'identifier ' => $ uuid ,
674
+ 'type ' => $ type ,
675
+ 'path ' => $ path ,
676
+ 'local_name ' => $ localName ,
677
+ 'namespace ' => $ namespace ,
678
+ 'parent ' => PathHelper::getParentPath ($ path ),
664
679
'workspace_name ' => $ this ->workspaceName ,
665
- 'props ' => $ propsData ['dom ' ]->saveXML (),
666
- 'depth ' => PathHelper::getPathDepth ($ path ),
667
- 'parent_a ' => PathHelper::getParentPath ($ path ),
680
+ 'props ' => $ propsData ['stringDom ' ]->saveXML (),
681
+ 'numerical_props ' => $ propsData ['numericalDom ' ] ? $ propsData ['numericalDom ' ]->saveXML () : null ,
682
+ 'depth ' => PathHelper::getPathDepth ($ path ),
683
+ 'parent_a ' => PathHelper::getParentPath ($ path ),
668
684
));
669
685
} catch (\Exception $ e ) {
670
686
if ($ e instanceof \PDOException || $ e instanceof DBALException) {
@@ -684,7 +700,13 @@ private function syncNode($uuid, $path, $type, $isNewNode, $props = array(), $pr
684
700
if (!$ nodeId ) {
685
701
throw new RepositoryException ("nodeId for $ path not found " );
686
702
}
687
- $ this ->conn ->update ('phpcr_nodes ' , array ('props ' => $ propsData ['dom ' ]->saveXML ()), array ('id ' => $ nodeId ));
703
+
704
+ $ this ->conn ->update ('phpcr_nodes ' , array (
705
+ 'props ' => $ propsData ['stringDom ' ]->saveXML (),
706
+ 'numerical_props ' => $ propsData ['numericalDom ' ] ? $ propsData ['numericalDom ' ]->saveXML () : null ,
707
+ ),
708
+ array ('id ' => $ nodeId )
709
+ );
688
710
}
689
711
690
712
$ this ->nodeIdentifiers [$ path ] = $ uuid ;
@@ -853,6 +875,7 @@ public static function xmlToProps($xml, ValueConverter $valueConverter, $filter
853
875
}
854
876
855
877
$ values = array ();
878
+
856
879
$ type = PropertyType::valueFromName ($ propertyNode ->getAttribute ('sv:type ' ));
857
880
foreach ($ propertyNode ->childNodes as $ valueNode ) {
858
881
switch ($ type ) {
@@ -912,7 +935,11 @@ public static function xmlToProps($xml, ValueConverter $valueConverter, $filter
912
935
* @param array $properties
913
936
* @param boolean $inlineBinaries
914
937
*
915
- * @return array ('dom' => $dom, 'binaryData' => streams, 'references' => array('type' => INT, 'values' => array(UUIDs)))
938
+ * @return array (
939
+ * 'stringDom' => $stringDom,
940
+ * 'numericalDom' => $numericalDom',
941
+ * 'binaryData' => streams,
942
+ * 'references' => array('type' => INT, 'values' => array(UUIDs)))
916
943
*/
917
944
private function propsToXML ($ properties , $ inlineBinaries = false )
918
945
{
@@ -925,20 +952,16 @@ private function propsToXML($properties, $inlineBinaries = false)
925
952
'rep ' => "internal " ,
926
953
);
927
954
928
- $ dom = new \DOMDocument ('1.0 ' , 'UTF-8 ' );
929
- $ rootNode = $ dom ->createElement ('sv:node ' );
930
- foreach ($ namespaces as $ namespace => $ uri ) {
931
- $ rootNode ->setAttribute ('xmlns: ' . $ namespace , $ uri );
932
- }
933
- $ dom ->appendChild ($ rootNode );
955
+ $ doms = array (
956
+ 'stringDom ' => array (),
957
+ 'numericalDom ' => array (),
958
+ );
934
959
935
960
$ binaryData = $ references = array ();
961
+
936
962
foreach ($ properties as $ property ) {
937
- /* @var $property Property */
938
- $ propertyNode = $ dom ->createElement ('sv:property ' );
939
- $ propertyNode ->setAttribute ('sv:name ' , $ property ->getName ());
940
- $ propertyNode ->setAttribute ('sv:type ' , PropertyType::nameFromValue ($ property ->getType ()));
941
- $ propertyNode ->setAttribute ('sv:multi-valued ' , $ property ->isMultiple () ? '1 ' : '0 ' );
963
+
964
+ $ targetDoms = array ('stringDom ' );
942
965
943
966
switch ($ property ->getType ()) {
944
967
case PropertyType::WEAKREFERENCE :
@@ -955,12 +978,14 @@ private function propsToXML($properties, $inlineBinaries = false)
955
978
break ;
956
979
case PropertyType::DECIMAL :
957
980
$ values = $ property ->getDecimal ();
981
+ $ targetDoms [] = 'numericalDom ' ;
958
982
break ;
959
983
case PropertyType::BOOLEAN :
960
984
$ values = array_map ('intval ' , (array ) $ property ->getBoolean ());
961
985
break ;
962
986
case PropertyType::LONG :
963
987
$ values = $ property ->getLong ();
988
+ $ targetDoms [] = 'numericalDom ' ;
964
989
break ;
965
990
case PropertyType::BINARY :
966
991
if ($ property ->isNew () || $ property ->isModified ()) {
@@ -998,26 +1023,66 @@ private function propsToXML($properties, $inlineBinaries = false)
998
1023
break ;
999
1024
case PropertyType::DOUBLE :
1000
1025
$ values = $ property ->getDouble ();
1026
+ $ targetDoms [] = 'numericalDom ' ;
1001
1027
break ;
1002
1028
default :
1003
1029
throw new RepositoryException ('unknown type ' .$ property ->getType ());
1004
1030
}
1005
1031
1006
- $ lengths = (array ) $ property ->getLength ();
1007
- foreach ((array ) $ values as $ key => $ value ) {
1008
- $ element = $ propertyNode ->appendChild ($ dom ->createElement ('sv:value ' ));
1009
- $ element ->appendChild ($ dom ->createTextNode ($ value ));
1010
- if (isset ($ lengths [$ key ])) {
1011
- $ lengthAttribute = $ dom ->createAttribute ('length ' );
1012
- $ lengthAttribute ->value = $ lengths [$ key ];
1013
- $ element ->appendChild ($ lengthAttribute );
1032
+ foreach ($ targetDoms as $ targetDom ) {
1033
+ $ doms [$ targetDom ][] = array (
1034
+ 'name ' => $ property ->getName (),
1035
+ 'type ' => PropertyType::nameFromValue ($ property ->getType ()),
1036
+ 'multiple ' => $ property ->isMultiple (),
1037
+ 'lengths ' => (array ) $ property ->getLength (),
1038
+ 'values ' => $ values ,
1039
+ );
1040
+ }
1041
+ }
1042
+
1043
+ $ ret = array (
1044
+ 'stringDom ' => null ,
1045
+ 'numericalDom ' => null ,
1046
+ 'binaryData ' => $ binaryData ,
1047
+ 'references ' => $ references
1048
+ );
1049
+
1050
+ foreach ($ doms as $ targetDom => $ properties ) {
1051
+
1052
+ $ dom = new \DOMDocument ('1.0 ' , 'UTF-8 ' );
1053
+ $ rootNode = $ dom ->createElement ('sv:node ' );
1054
+ foreach ($ namespaces as $ namespace => $ uri ) {
1055
+ $ rootNode ->setAttribute ('xmlns: ' . $ namespace , $ uri );
1056
+ }
1057
+ $ dom ->appendChild ($ rootNode );
1058
+
1059
+ foreach ($ properties as $ property ) {
1060
+
1061
+ /* @var $property Property */
1062
+ $ propertyNode = $ dom ->createElement ('sv:property ' );
1063
+ $ propertyNode ->setAttribute ('sv:name ' , $ property ['name ' ]);
1064
+ $ propertyNode ->setAttribute ('sv:type ' , $ property ['type ' ]);
1065
+ $ propertyNode ->setAttribute ('sv:multi-valued ' , $ property ['multiple ' ] ? '1 ' : '0 ' );
1066
+ $ lengths = (array ) $ property ['lengths ' ];
1067
+ foreach ((array ) $ property ['values ' ] as $ key => $ value ) {
1068
+ $ element = $ propertyNode ->appendChild ($ dom ->createElement ('sv:value ' ));
1069
+ $ element ->appendChild ($ dom ->createTextNode ($ value ));
1070
+ if (isset ($ lengths [$ key ])) {
1071
+ $ lengthAttribute = $ dom ->createAttribute ('length ' );
1072
+ $ lengthAttribute ->value = $ lengths [$ key ];
1073
+ $ element ->appendChild ($ lengthAttribute );
1074
+ }
1014
1075
}
1076
+
1077
+ $ rootNode ->appendChild ($ propertyNode );
1015
1078
}
1016
1079
1017
- $ rootNode ->appendChild ($ propertyNode );
1080
+ if (count ($ properties )) {
1081
+ $ ret [$ targetDom ] = $ dom ;
1082
+ }
1018
1083
}
1019
1084
1020
- return array ( ' dom ' => $ dom , ' binaryData ' => $ binaryData , ' references ' => $ references ) ;
1085
+ return $ ret ;
1021
1086
}
1022
1087
1023
1088
/**
0 commit comments