@@ -12,13 +12,13 @@ function copypage( $pageName, $recursivelyCalled = true ) {
1212 $ parts = explode ( ': ' , $ pageName );
1313 $ content = $ privateApi ->readPage ($ pageName );
1414
15- if ( empty ($ content ) ) {
16- // write to file that reading failed
17- echo "Page read error...Check if page exists and is accessible \n" ;
18- echo "logging page name in failed_pages.txt \n" ;
19- file_put_contents ( 'failed_pages.txt ' , $ pageName . "\n" , FILE_APPEND );
20- return ;
21- }
15+ if ( empty ($ content ) ) {
16+ // write to file that reading failed
17+ echo "Page read error...Check if page exists and is accessible \n" ;
18+ echo "logging page name in failed_pages.txt \n" ;
19+ file_put_contents ( 'failed_pages.txt ' , $ pageName . "\n" , FILE_APPEND );
20+ return ;
21+ }
2222
2323 if ( count ( $ parts ) === 2 && $ parts [0 ] === 'File ' ) { // files are handled here
2424 $ rawFileUrl = $ privateApi ->getFileUrl ($ pageName );
@@ -43,28 +43,32 @@ function copypage( $pageName, $recursivelyCalled = true ) {
4343 }
4444
4545 // now copy normal page
46- if ($ settings ['create ' ])
47- {
46+ if ($ settings ['create ' ]) {
4847 $ data = $ publicApi ->createPage ($ pageName , $ content );
4948 } else {
5049 $ data = $ publicApi ->editPage ($ pageName , $ content );
5150 }
51+
5252 if ( $ data == null ) {
5353 // write to file that copy failed
5454 echo "logging page name in failed_pages.txt \n" ;
5555 file_put_contents ( 'failed_pages.txt ' , $ pageName . "\n" , FILE_APPEND );
5656 }
5757
58- // Now import images linked on the page
59- echo "Finding file links in $ pageName ... \n" ;
60- $ result = $ privateApi ->listImagesOnPage ($ pageName );
61- if ( $ result ) {
62- foreach ( $ result as $ image ) {
63- echo "Link found to " . (string )$ image ['title ' ] . " \n" ;
64- copypage ( (string )$ image ['title ' ] );
58+ if ($ settings ['copy_images ' ]) {
59+ // Now import images linked on the page
60+ echo "Finding file links in $ pageName ... \n" ;
61+ $ result = $ privateApi ->listImagesOnPage ($ pageName );
62+ if ( $ result ) {
63+ foreach ( $ result as $ image ) {
64+ echo "Link found to " . (string )$ image ['title ' ] . " \n" ;
65+ copypage ( (string )$ image ['title ' ] );
66+ }
67+ } else {
68+ echo "No file links found \n" ;
6569 }
6670 } else {
67- echo "No file links found \n" ;
71+ echo "Skipping files \n" ;
6872 }
6973
7074 // Now copy category members too
0 commit comments