@@ -52,6 +52,13 @@ class WebformAllFormSubmissions extends ResourceBase {
5252 */
5353 private $ webformHelper ;
5454
55+ /**
56+ * The database connection.
57+ *
58+ * @var \Drupal\Core\Database\Connection
59+ */
60+ private $ database ;
61+
5562 /**
5663 * {@inheritdoc}
5764 *
@@ -63,6 +70,7 @@ public static function create(ContainerInterface $container, array $configuratio
6370 $ instance ->entityTypeManager = $ container ->get ('entity_type.manager ' );
6471 $ instance ->currentRequest = $ container ->get ('request_stack ' )->getCurrentRequest ();
6572 $ instance ->webformHelper = $ container ->get (WebformHelper::class);
73+ $ instance ->database = $ container ->get ('database ' );
6674
6775 return $ instance ;
6876 }
@@ -112,32 +120,17 @@ public function get(string $webform_id): ModifiedResourceResponse {
112120
113121 $ result = ['webform_id ' => $ webform_id ];
114122
115- try {
116- $ submissionEntityStorage = $ this ->entityTypeManager ->getStorage ('webform_submission ' );
117- }
118- catch (InvalidPluginDefinitionException | PluginNotFoundException $ e ) {
119- $ errors = [
120- 'error ' => [
121- 'message ' => $ this ->t ('Could not load webform submission storage ' ),
122- ],
123- ];
124-
125- return new ModifiedResourceResponse ($ errors , Response::HTTP_INTERNAL_SERVER_ERROR );
126- }
127-
128- // Query for webform submissions with this webform_id.
129- $ submissionQuery = $ submissionEntityStorage ->getQuery ()
130- ->condition ('webform_id ' , $ webform_id );
131-
132123 $ requestQuery = $ this ->currentRequest ->query ;
133124
125+ $ query = 'SELECT sid, uuid FROM webform_submission WHERE webform_id = :webform_id ' ;
126+
134127 foreach (self ::ALLOWED_DATETIME_QUERY_PARAMS as $ param => $ operator ) {
135128 $ value = $ requestQuery ->get ($ param );
136129
137130 if (!empty ($ value )) {
138131 try {
139132 $ dateTime = new \DateTimeImmutable ($ value );
140- $ submissionQuery -> condition ( ' created ' , $ dateTime ->getTimestamp (), $ operator );
133+ $ query .= sprintf ( ' AND created %s %s ' , $ operator , $ dateTime ->getTimestamp ());
141134 $ result [$ param ] = $ value ;
142135 }
143136 catch (\Exception $ e ) {
@@ -152,9 +145,10 @@ public function get(string $webform_id): ModifiedResourceResponse {
152145 }
153146 }
154147
155- // Complete query.
156- $ submissionQuery ->accessCheck (FALSE );
157- $ sids = $ submissionQuery ->execute ();
148+ $ submissions = $ this ->database ->query (
149+ $ query ,
150+ [':webform_id ' => $ webform_id ]
151+ )->fetchAllKeyed ();
158152
159153 // Generate submission URLs.
160154 try {
@@ -163,12 +157,12 @@ public function get(string $webform_id): ModifiedResourceResponse {
163157 'rest.webform_rest_submission.GET ' ,
164158 [
165159 'webform_id ' => $ webform_id ,
166- 'uuid ' => $ submission-> uuid () ,
160+ 'uuid ' => $ submission ,
167161 ]
168162 )
169163 ->setAbsolute ()
170164 ->toString (TRUE )->getGeneratedUrl (),
171- $ submissionEntityStorage -> loadMultiple ( $ sids ?: [])
165+ $ submissions ?: []
172166 );
173167 }
174168 catch (\Exception $ e ) {
0 commit comments