@@ -1294,7 +1294,7 @@ private function exportFileData(File $file): void
12941294 // Get the file size
12951295 $ fileSize = $ file ->getSize ();
12961296
1297- if ($ end > $ fileSize ) {
1297+ if ($ end >= $ fileSize ) {
12981298 $ end = $ fileSize - 1 ;
12991299 }
13001300
@@ -1318,7 +1318,7 @@ private function exportFileData(File $file): void
13181318 $ start += Transfer::STORAGE_MAX_CHUNK_SIZE ;
13191319 $ end += Transfer::STORAGE_MAX_CHUNK_SIZE ;
13201320
1321- if ($ end > $ fileSize ) {
1321+ if ($ end >= $ fileSize ) {
13221322 $ end = $ fileSize - 1 ;
13231323 }
13241324 }
@@ -1341,9 +1341,8 @@ protected function exportGroupFunctions(int $batchSize, array $resources): void
13411341 }
13421342
13431343 try {
1344- if (\in_array (Resource::TYPE_DEPLOYMENT , $ resources )) {
1345- $ this ->exportDeployments ($ batchSize , true );
1346- }
1344+ $ exportOnlyActive = !\in_array (Resource::TYPE_DEPLOYMENT , $ resources );
1345+ $ this ->exportDeployments ($ batchSize , $ exportOnlyActive );
13471346 } catch (\Throwable $ e ) {
13481347 $ this ->addError (new Exception (
13491348 Resource::TYPE_DEPLOYMENT ,
@@ -1372,9 +1371,8 @@ protected function exportGroupSites(int $batchSize, array $resources): void
13721371 }
13731372
13741373 try {
1375- if (\in_array (Resource::TYPE_SITE_DEPLOYMENT , $ resources )) {
1376- $ this ->exportSiteDeployments ($ batchSize , true );
1377- }
1374+ $ exportOnlyActive = !\in_array (Resource::TYPE_SITE_DEPLOYMENT , $ resources );
1375+ $ this ->exportSiteDeployments ($ batchSize , $ exportOnlyActive );
13781376 } catch (\Throwable $ e ) {
13791377 $ this ->addError (new Exception (
13801378 Resource::TYPE_SITE_DEPLOYMENT ,
@@ -1466,8 +1464,13 @@ private function exportDeployments(int $batchSize, bool $exportOnlyActive = fals
14661464 /** @var Func $func */
14671465 $ lastDocument = null ;
14681466
1469- if ($ exportOnlyActive && $ func ->getActiveDeployment ()) {
1470- $ deployment = $ this ->functions ->getDeployment ($ func ->getId (), $ func ->getActiveDeployment ());
1467+ if ($ exportOnlyActive ) {
1468+ $ activeDeploymentId = $ func ->getActiveDeployment ();
1469+ if (empty ($ activeDeploymentId )) {
1470+ continue ; // active-only mode: nothing to export for this function
1471+ }
1472+
1473+ $ deployment = $ this ->functions ->getDeployment ($ func ->getId (), $ activeDeploymentId );
14711474
14721475 try {
14731476 $ this ->exportDeploymentData ($ func , $ deployment );
@@ -1527,8 +1530,8 @@ private function exportDeploymentData(Func $func, array $deployment): void
15271530 $ responseHeaders
15281531 );
15291532
1530- // Content-Length header was missing, file is less than max buffer size.
1531- if (!array_key_exists ('Content-Length ' , $ responseHeaders )) {
1533+ // content-length header missing, file is less than max buffer size
1534+ if (!array_key_exists ('content-length ' , $ responseHeaders )) {
15321535 $ file = $ this ->call (
15331536 'GET ' ,
15341537 "/functions/ {$ func ->getId ()}/deployments/ {$ deployment ['$id ' ]}/download " ,
@@ -1537,7 +1540,7 @@ private function exportDeploymentData(Func $func, array $deployment): void
15371540 $ responseHeaders
15381541 );
15391542
1540- $ size = mb_strlen ($ file );
1543+ $ size = strlen ($ file );
15411544
15421545 if ($ end > $ size ) {
15431546 $ end = $ size - 1 ;
@@ -1560,7 +1563,11 @@ private function exportDeploymentData(Func $func, array $deployment): void
15601563 return ;
15611564 }
15621565
1563- $ fileSize = $ responseHeaders ['Content-Length ' ];
1566+ $ fileSize = $ responseHeaders ['content-length ' ];
1567+
1568+ if ($ end >= $ fileSize ) {
1569+ $ end = $ fileSize - 1 ;
1570+ }
15641571
15651572 $ deployment = new Deployment (
15661573 $ deployment ['$id ' ],
@@ -1595,7 +1602,7 @@ private function exportDeploymentData(Func $func, array $deployment): void
15951602 $ start += Transfer::STORAGE_MAX_CHUNK_SIZE ;
15961603 $ end += Transfer::STORAGE_MAX_CHUNK_SIZE ;
15971604
1598- if ($ end > $ fileSize ) {
1605+ if ($ end >= $ fileSize ) {
15991606 $ end = $ fileSize - 1 ;
16001607 }
16011608 }
@@ -1684,8 +1691,13 @@ private function exportSiteDeployments(int $batchSize, bool $exportOnlyActive =
16841691 /** @var Site $site */
16851692 $ lastDocument = null ;
16861693
1687- if ($ exportOnlyActive && $ site ->getActiveDeployment ()) {
1688- $ deployment = $ this ->sites ->getDeployment ($ site ->getId (), $ site ->getActiveDeployment ());
1694+ if ($ exportOnlyActive ) {
1695+ $ activeDeploymentId = $ site ->getActiveDeployment ();
1696+ if (empty ($ activeDeploymentId )) {
1697+ continue ; // active-only mode: nothing to export for this site
1698+ }
1699+
1700+ $ deployment = $ this ->sites ->getDeployment ($ site ->getId (), $ activeDeploymentId );
16891701
16901702 try {
16911703 $ this ->exportSiteDeploymentData ($ site , $ deployment );
@@ -1743,7 +1755,7 @@ private function exportSiteDeploymentData(Site $site, array $deployment): void
17431755 $ responseHeaders
17441756 );
17451757
1746- if (!\array_key_exists ('Content-Length ' , $ responseHeaders )) {
1758+ if (!\array_key_exists ('content-length ' , $ responseHeaders )) {
17471759 $ file = $ this ->call (
17481760 'GET ' ,
17491761 "/sites/ {$ site ->getId ()}/deployments/ {$ deployment ['$id ' ]}/download " ,
@@ -1752,7 +1764,7 @@ private function exportSiteDeploymentData(Site $site, array $deployment): void
17521764 $ responseHeaders
17531765 );
17541766
1755- $ size = mb_strlen ($ file );
1767+ $ size = strlen ($ file );
17561768
17571769 if ($ end > $ size ) {
17581770 $ end = $ size - 1 ;
@@ -1774,7 +1786,11 @@ private function exportSiteDeploymentData(Site $site, array $deployment): void
17741786 return ;
17751787 }
17761788
1777- $ fileSize = $ responseHeaders ['Content-Length ' ];
1789+ $ fileSize = $ responseHeaders ['content-length ' ];
1790+
1791+ if ($ end >= $ fileSize ) {
1792+ $ end = $ fileSize - 1 ;
1793+ }
17781794
17791795 $ siteDeployment = new SiteDeployment (
17801796 $ deployment ['$id ' ],
@@ -1805,7 +1821,7 @@ private function exportSiteDeploymentData(Site $site, array $deployment): void
18051821 $ start += Transfer::STORAGE_MAX_CHUNK_SIZE ;
18061822 $ end += Transfer::STORAGE_MAX_CHUNK_SIZE ;
18071823
1808- if ($ end > $ fileSize ) {
1824+ if ($ end >= $ fileSize ) {
18091825 $ end = $ fileSize - 1 ;
18101826 }
18111827 }
0 commit comments