Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
spreadsheets
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
spreadsheets
Commits
d922eed1
Commit
d922eed1
authored
Feb 10, 2023
by
Paulo Calado
Committed by
Paulo Calado
Feb 10, 2023
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3340870
by kallado: Return empty array on Exception in function getdata
parent
a0d2f06c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/SpreadSheets.php
+13
-7
13 additions, 7 deletions
src/SpreadSheets.php
with
13 additions
and
7 deletions
src/SpreadSheets.php
+
13
−
7
View file @
d922eed1
...
...
@@ -6,6 +6,7 @@ use Google_Client;
use
Google_Service_Sheets
;
use
Drupal\file\Entity\File
;
use
Google_Service_Drive
;
use
Google\Service\Exception
;
/**
* Class for the service javali_sheets.base .
...
...
@@ -28,7 +29,7 @@ class SpreadSheets {
*
* @var string
*/
private
$sheet
I
d
;
private
$sheet
_i
d
;
/**
* The range from config.
...
...
@@ -86,7 +87,7 @@ class SpreadSheets {
* @return array
* an array with the sheet data
*/
public
function
getdata
()
{
public
function
getdata
(
$format
=
'FORMATTED_VALUE'
)
{
$client
=
$this
->
client
;
$service
=
new
\Google_Service_Sheets
(
$client
);
$spreadsheetId
=
$this
->
sheet_id
;
...
...
@@ -107,17 +108,22 @@ class SpreadSheets {
if
(
!
$this
->
myArrayContainsWord
(
$idCats
,
$name
))
{
return
$messenger
->
addMessage
(
'Sheet not found'
,
'error'
);
}
$options
=
[
'valueRenderOption'
=>
$format
];
$range_format
=
!
empty
(
$this
->
range
)
?
$this
->
sheetName
.
'!'
.
$this
->
range
:
$this
->
sheetName
;
$response
=
$service
->
spreadsheets_values
->
get
(
$spreadsheetId
,
$range_format
);
$response
=
$service
->
spreadsheets_values
->
get
(
$spreadsheetId
,
$range_format
,
$options
);
if
(
!
empty
(
$response
->
values
))
{
return
$response
->
values
;
}
}
catch
(
\Google_Service_Exception
$e
)
{
$error
=
json_decode
(
$e
->
getMessage
(),
TRUE
);
return
$messenger
->
addMessage
(
$error
[
'error'
][
'message'
],
'error'
);
catch
(
Exception
$e
)
{
$message
=
json_decode
(
$e
->
getMessage
(),
true
);
$messenger
->
addMessage
(
$message
[
'error'
][
'message'
],
'error'
);
return
[];
}
return
$messenger
->
addMessage
(
'An error ocurred!'
,
'error'
);
$messenger
->
addMessage
(
'An error ocurred!'
,
'error'
);
return
[];
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment