@@ -34,36 +34,68 @@ function xmldb_block_rss_thumbnails_upgrade($oldversion) {
34
34
// Automatically generated Moodle v3.9.0 release upgrade line.
35
35
// Put any upgrade step following this.
36
36
$ dbman = $ DB ->get_manager ();
37
- if ($ oldversion < 2022091502 ) {
37
+ if ($ oldversion < 2022111004 ) {
38
38
39
- // Define table block_rss_thumbnails to be created.
40
- $ table = new xmldb_table ('block_rss_thumbnails ' );
41
-
42
- // Adding fields to table block_rss_thumbnails.
43
- $ table ->add_field ('id ' , XMLDB_TYPE_INTEGER , '10 ' , null , XMLDB_NOTNULL , XMLDB_SEQUENCE , null );
44
- $ table ->add_field ('userid ' , XMLDB_TYPE_INTEGER , '10 ' , null , XMLDB_NOTNULL , null , '0 ' );
45
- $ table ->add_field ('title ' , XMLDB_TYPE_TEXT , null , null , XMLDB_NOTNULL , null , null );
46
- $ table ->add_field ('preferredtitle ' , XMLDB_TYPE_CHAR , '64 ' , null , XMLDB_NOTNULL , null , null );
47
- $ table ->add_field ('description ' , XMLDB_TYPE_TEXT , null , null , XMLDB_NOTNULL , null , null );
48
- $ table ->add_field ('shared ' , XMLDB_TYPE_INTEGER , '2 ' , null , XMLDB_NOTNULL , null , '0 ' );
49
- $ table ->add_field ('url ' , XMLDB_TYPE_CHAR , '255 ' , null , XMLDB_NOTNULL , null , null );
50
- $ table ->add_field ('skiptime ' , XMLDB_TYPE_INTEGER , '10 ' , null , XMLDB_NOTNULL , null , '0 ' );
51
- $ table ->add_field ('skipuntil ' , XMLDB_TYPE_INTEGER , '10 ' , null , XMLDB_NOTNULL , null , '0 ' );
52
-
53
- // Adding keys to table block_rss_thumbnails.
54
- $ table ->add_key ('primary ' , XMLDB_KEY_PRIMARY , ['id ' ]);
39
+ $ table = create_block_rss_thumbnails_table ();
40
+ $ params = ['blockname ' => 'rss_thumbnails ' ];
55
41
56
42
// Conditionally launch create table for block_rss_thumbnails.
57
43
if (!$ dbman ->table_exists ($ table )) {
58
44
$ dbman ->create_table ($ table );
59
45
}
46
+ if ($ DB ->record_exists ('block_instances ' , $ params )) {
47
+ if ($ dbman ->table_exists ('block_rss_client ' )) {
48
+ $ rssfeeds = $ DB ->get_records ('block_rss_client ' );
49
+ $ DB ->insert_records ('block_rss_thumbnails ' , $ rssfeeds );
50
+ }
51
+ $ blockinstances = $ DB ->get_records ('block_instances ' , ['blockname ' => 'rss_thumbnails ' ]);
52
+ foreach ($ blockinstances as $ blockinstance ) {
53
+ // Access to block's configdata.
54
+ $ blockconfig = unserialize (base64_decode ($ blockinstance ->configdata ));
55
+
56
+ // Update caroussel speed variable that changed into carousseldelay for semantical reasons.
57
+ $ blockconfig ->carousseldelay = $ blockconfig ->carousselspeed ;
58
+ $ blockconfig ->numentries = $ blockconfig ->shownumentries ;
59
+
60
+ $ newblockinstance = clone $ blockinstance ;
61
+ // Re-serialize block's configdata.
62
+ $ newblockinstance ->configdata = base64_encode (serialize ($ blockconfig ));
63
+
64
+ $ DB ->update_record ('block_instances ' , $ newblockinstance );
65
+ }
66
+ }
60
67
61
68
// Rss_thumbnails savepoint reached.
62
- upgrade_block_savepoint (true , 2022091502 , 'rss_thumbnails ' );
69
+ upgrade_block_savepoint (true , 2022111004 , 'rss_thumbnails ' );
63
70
}
64
71
65
72
// Automatically generated Moodle v4.0.0 release upgrade line.
66
73
// Put any upgrade step following this.
67
74
68
75
return true ;
69
76
}
77
+
78
+ /**
79
+ * Creates an empty block_rss_thumbnails table by adding to it all the fields it needs and setting up the right primary key.
80
+ *
81
+ * @return xmldb_table
82
+ */
83
+ function create_block_rss_thumbnails_table (): xmldb_table {
84
+ // Define table block_rss_thumbnails to be created.
85
+ $ table = new xmldb_table ('block_rss_thumbnails ' );
86
+
87
+ // Adding fields to table block_rss_thumbnails.
88
+ $ table ->add_field ('id ' , XMLDB_TYPE_INTEGER , '10 ' , null , XMLDB_NOTNULL , XMLDB_SEQUENCE , null );
89
+ $ table ->add_field ('userid ' , XMLDB_TYPE_INTEGER , '10 ' , null , XMLDB_NOTNULL , null , '0 ' );
90
+ $ table ->add_field ('title ' , XMLDB_TYPE_TEXT , null , null , XMLDB_NOTNULL , null , null );
91
+ $ table ->add_field ('preferredtitle ' , XMLDB_TYPE_CHAR , '64 ' , null , XMLDB_NOTNULL , null , null );
92
+ $ table ->add_field ('description ' , XMLDB_TYPE_TEXT , null , null , XMLDB_NOTNULL , null , null );
93
+ $ table ->add_field ('shared ' , XMLDB_TYPE_INTEGER , '2 ' , null , XMLDB_NOTNULL , null , '0 ' );
94
+ $ table ->add_field ('url ' , XMLDB_TYPE_CHAR , '255 ' , null , XMLDB_NOTNULL , null , null );
95
+ $ table ->add_field ('skiptime ' , XMLDB_TYPE_INTEGER , '10 ' , null , XMLDB_NOTNULL , null , '0 ' );
96
+ $ table ->add_field ('skipuntil ' , XMLDB_TYPE_INTEGER , '10 ' , null , XMLDB_NOTNULL , null , '0 ' );
97
+
98
+ // Adding keys to table block_rss_thumbnails.
99
+ $ table ->add_key ('primary ' , XMLDB_KEY_PRIMARY , ['id ' ]);
100
+ return $ table ;
101
+ }
0 commit comments