Skip to content

Commit a185291

Browse files
Stefan HeimesStefan Heimes
Stefan Heimes
authored and
Stefan Heimes
committed
Small bugfixes
- Add the response if sync was canceld - Correct filesync for large files
1 parent 3139992 commit a185291

File tree

2 files changed

+53
-34
lines changed

2 files changed

+53
-34
lines changed

classes/SyncCtoFiles.php

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,52 +1420,67 @@ public function splitFiles($strSrcFile, $strDesFolder, $strDesFile, $intSizeLimi
14201420
*
14211421
* @CtoCommunication Enable
14221422
*
1423-
* @param type $strSplitname
1424-
* @param type $intSplitcount
1425-
* @param type $strMovepath
1426-
* @param type $strMD5
1423+
* @param string $splitname
1424+
* @param int|string $splitcount
1425+
* @param string $movepath
1426+
* @param string $md5
14271427
*
1428-
* @return type
1428+
* @return boolean
1429+
*
1430+
* @throws Exception
14291431
*/
1430-
public function rebuildSplitFiles($strSplitname, $intSplitcount, $strMovepath, $strMD5)
1431-
{
1432-
// Build savepath
1433-
$strSavePath = $this->objSyncCtoHelper->standardizePath($GLOBALS['SYC_PATH']['tmp'], "sync", $strMovepath);
1432+
public function rebuildSplitFiles(
1433+
string $splitname,
1434+
int|string $splitcount,
1435+
string $movepath,
1436+
string $md5
1437+
) {
1438+
$strSavePath = $this
1439+
->objSyncCtoHelper
1440+
->standardizePath($GLOBALS['SYC_PATH']['tmp'], "sync", $movepath)
1441+
;
14341442

14351443
// Create Folder
1436-
$objFolder = new Folder(dirname($strSavePath));
1444+
try {
1445+
new Folder(dirname($strSavePath));
1446+
} catch (Exception $e) {
1447+
throw new Exception(
1448+
sprintf(
1449+
'Could not create folder "%s". Error: %s',
1450+
dirname($strSavePath),
1451+
$e->getMessage()
1452+
)
1453+
);
1454+
}
14371455

1438-
// Run for each part file
1439-
for ($i = 0; $i < $intSplitcount; $i++) {
1440-
// Build path for part file
1441-
$strReadFile = $this->objSyncCtoHelper->standardizePath($GLOBALS['SYC_PATH']['tmp'], $strSplitname, $strSplitname . ".sync" . $i);
1456+
$hanFileWhole = fopen(
1457+
$this->objSyncCtoHelper->getContaoRoot()
1458+
. DIRECTORY_SEPARATOR
1459+
. $strSavePath,
1460+
"a+"
1461+
);
1462+
for ($i = 0; $i < $splitcount; $i++) {
1463+
$strReadFile = $this
1464+
->objSyncCtoHelper
1465+
->standardizePath($GLOBALS['SYC_PATH']['tmp'], $splitname, $splitname . ".sync" . $i)
1466+
;
14421467

14431468
// Check if file exists
14441469
if (!file_exists($this->objSyncCtoHelper->getContaoRoot() . DIRECTORY_SEPARATOR . $strReadFile)) {
1445-
throw new Exception(vsprintf($GLOBALS['TL_LANG']['ERR']['unknown_file'], array($strSplitname . ".sync" . $i)));
1470+
throw new Exception(vsprintf($GLOBALS['TL_LANG']['ERR']['unknown_file'], array($splitname . ".sync" . $i)));
14461471
}
14471472

1448-
// Create new file objects
1449-
$objFilePart = new File($strReadFile);
1450-
$hanFileWhole = fopen($this->objSyncCtoHelper->getContaoRoot() . DIRECTORY_SEPARATOR . $strSavePath, "a+");
1451-
1452-
// Write part file to main file
1453-
fwrite($hanFileWhole, $objFilePart->getContent());
1454-
1455-
// Close objects
1456-
$objFilePart->close();
1457-
fclose($hanFileWhole);
1458-
1459-
// Free up memory
1460-
unset($objFilePart);
1461-
unset($hanFileWhole);
1462-
1463-
// wait
1464-
sleep(1);
1473+
fwrite(
1474+
$hanFileWhole,
1475+
file_get_contents($this->objSyncCtoHelper->getContaoRoot() . DIRECTORY_SEPARATOR . $strReadFile)
1476+
);
14651477
}
14661478

1479+
fclose($hanFileWhole);
1480+
unset($hanFileWhole);
1481+
14671482
// Check MD5 Checksum
1468-
if (md5_file($this->objSyncCtoHelper->getContaoRoot() . DIRECTORY_SEPARATOR . $strSavePath) != $strMD5) {
1483+
if (md5_file($this->objSyncCtoHelper->getContaoRoot() . DIRECTORY_SEPARATOR . $strSavePath) != $md5) {
14691484
throw new Exception($GLOBALS['TL_LANG']['ERR']['checksum_error']);
14701485
}
14711486

src/Controller/ClientController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,11 @@ public function __invoke(): Response
431431
// Hidden control
432432
$this->templateVars['showControl'] = false;
433433

434-
return new Response('');
434+
$this->setTemplateVars();
435+
return $this->render(
436+
'@SyncCto/be_syncCto_steps.html.twig',
437+
$this->templateVars
438+
);
435439
}
436440

437441
// Which table is in use

0 commit comments

Comments
 (0)