Version 5.0.13
This commit is contained in:
1 parent
b89858b2ff
commit
5efe744c5f
1407 files changed
+69690
-30177
No files matched your search
@@ -11,6 +11,9 @@
|
||||
|
||||
namespace IPS\cms\setup\upg_5000029;
|
||||
|
||||
use IPS\cms\Pages\Page;
|
||||
use IPS\Db;
|
||||
use IPS\Widget\Area;
|
||||
use function array_keys;
|
||||
use function array_merge;
|
||||
use function defined;
|
||||
@@ -38,67 +41,55 @@ class Upgrade
|
||||
public function step1() : bool|array
|
||||
{
|
||||
$areas = [];
|
||||
foreach( \IPS\Db::i()->select( '*', 'cms_page_widget_areas', [], 'area_page_id ASC' ) as $row )
|
||||
foreach( Db::i()->select( '*', 'cms_page_widget_areas', [], 'area_page_id ASC' ) as $row )
|
||||
{
|
||||
$areas[ $row['area_page_id'] ][ $row['area_area'] ] = $row;
|
||||
}
|
||||
|
||||
/* Now check to make sure that we have a col1 area and also that we don't have a database widget in header/footer/sidebar from v4 */
|
||||
/* Now check for a Database widget in the wrong area.
|
||||
We have to do this by database rows because if we try to build an area
|
||||
with an invalid widget (e.g. database in a protected area), it will just ignore the widget */
|
||||
foreach( $areas as $pageId => $areaRows )
|
||||
{
|
||||
if ( ! in_array( 'col1', array_keys( $areaRows ) ) )
|
||||
try
|
||||
{
|
||||
/* Insert one */
|
||||
\IPS\Db::i()->insert( 'cms_page_widget_areas', [
|
||||
'area_page_id' => $pageId,
|
||||
'area_widgets' => '[]',
|
||||
'area_area' => 'col1',
|
||||
'area_orientation' => 'vertical',
|
||||
'area_tree' => ''
|
||||
] );
|
||||
}
|
||||
$page = Page::load( $pageId );
|
||||
|
||||
/* Now check for a Database widget in the wrong area */
|
||||
foreach( [ 'header', 'footer', 'sidebar' ] as $protectedArea )
|
||||
{
|
||||
if ( in_array( $protectedArea, array_keys( $areaRows ) ) and $areaRows[ $protectedArea ]['area_widgets'] )
|
||||
foreach( [ 'header', 'footer', 'sidebar' ] as $protectedArea )
|
||||
{
|
||||
if( $widgets = json_decode( $areaRows[ $protectedArea ]['area_widgets'], true ) )
|
||||
if ( in_array( $protectedArea, array_keys( $areaRows ) ) and $areaRows[ $protectedArea ]['area_widgets'] )
|
||||
{
|
||||
$needsUpdating = false;
|
||||
$database = [];
|
||||
$newWidgets = [];
|
||||
foreach( $widgets as $widget )
|
||||
if( $widgets = json_decode( $areaRows[ $protectedArea ]['area_widgets'], true ) )
|
||||
{
|
||||
if ( $widget['app'] === 'cms' and $widget['key'] == 'Database' )
|
||||
foreach( $widgets as $idx => $widget )
|
||||
{
|
||||
/* Well, this shouldn't be here */
|
||||
$database = $widget;
|
||||
$needsUpdating = true;
|
||||
if ( $widget['app'] === 'cms' and $widget['key'] == 'Database' )
|
||||
{
|
||||
/* Let's load the main area for this page */
|
||||
$mainArea = $page->getAreasFromDatabase( 'col1' )['col1'] ?? new Area( [], 'col1' );
|
||||
$mainArea->addWidget( $widget );
|
||||
$page->saveArea( $mainArea, false );
|
||||
unset( $widgets[ $idx ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
/* If there are no more widgets here, delete the area entirely */
|
||||
if( empty( $widgets ) )
|
||||
{
|
||||
$newWidgets[] = $widget;
|
||||
Db::i()->delete( 'cms_page_widget_areas', [ 'area_area=? and area_page_id=?', $protectedArea, $pageId ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $needsUpdating )
|
||||
{
|
||||
/* Get any existing from the database for col1 if it exists */
|
||||
if( $col1 = json_decode( $areaRows['col1']['area_widgets'], true ) )
|
||||
{
|
||||
$database = array_merge( [ $database ], $col1 );
|
||||
}
|
||||
|
||||
/* Update the existing area */
|
||||
\IPS\Db::i()->update( 'cms_page_widget_areas', [ 'area_widgets' => json_encode( $newWidgets ) ], [ 'area_page_id=? and area_area=?', $pageId, $protectedArea ] );
|
||||
|
||||
/* Move the database across */
|
||||
\IPS\Db::i()->update( 'cms_page_widget_areas', [ 'area_widgets' => json_encode( [ $database ] ) ], [ 'area_page_id=? and area_area=?', $pageId, 'col1' ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
/* Page doesn't exist, we can just delete it */
|
||||
Db::i()->delete( 'cms_page_widget_areas', [ 'area_page_id=?', $pageId ] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
Reference in new issue
Block a user