Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup/restore of icons #9

Merged
merged 2 commits into from
Jul 24, 2024

Conversation

rogiervandongen
Copy link

Backup/restore of icons

Backup/restore of icons
Copy link
Collaborator

@gjb2048 gjb2048 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rogiervandongen Please see my comments and make changes as appropriate. I do appreciate that there is pure SQL already there and in the Moodle code but my understanding is that it should be avoided if at all possible. In addition there are other separate issues outside of the context of the pull that appear to be causing Code Checker to complain.


public function __construct($plugintype, $pluginname, $optigroup, $step) {
parent::__construct($plugintype, $pluginname, $optigroup, $step);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Customisation can be done for ALL activity types.
$courseiconwrapper = new backup_nested_element('courseicons');
$courseicon = new backup_nested_element('courseicon', [], ['name']);
$sql = 'SELECT DISTINCT m.name FROM {modules} m';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do all supported databases support 'DISTINCT'? Would it not be better to use a DB API call instead of pure SQL as recommended (I believe I've seen this in the Moodle developer documentation)?

$pluginwrapper->add_child($courseiconwrapper);
$courseiconwrapper->add_child($courseicon);

// This seems to work ere, we actually have the old course context available.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work? You don't sound sure.

'SELECT max(section) FROM {course_sections} WHERE course = ?',
[$this->step->get_task()->get_courseid()]);
$this->originalnumsections = (int)$maxsection;
'SELECT max(section) FROM {course_sections} WHERE course = ?',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto with previous SQL comment.


// Create one standard named plugin element (the visible container) using the base recommended name.
$pluginwrapper = new backup_nested_element($this->get_recommended_name());
// Connect to container
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs full stop.

// GAWD, I hate backup/restore. Unclear, messy, lacking. Just... plain... wrong.
// ELOY, YOUR IMPLEMENTATION SUCKS!
$customicon = new backup_nested_element('modicon', [], ['itemid', 'modname', 'oldctxid']);
$customicon->set_source_array([['itemid' => 0, 'modname' => $this->task->get_modulename(), 'oldctxid' => $modulecontextid]]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line too long.

if ($sectionnum > $numsections && $sectionnum > $this->originalnumsections) {
$DB->execute("UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?",
[$this->step->get_task()->get_courseid(), $sectionnum]);
[$this->step->get_task()->get_courseid(), $sectionnum]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the extra indentation?

*
* @var array
*/
protected static $modicons = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be defined at the top of the class? For maintainability and readability.

version.php Outdated
@@ -25,9 +25,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024050801;
$plugin->version = 2024050802;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a version bump? There is nothing that actually needs it here. Also version bumping in a code change commit makes it more difficult to back port. Better to version bump a new development sequence, commit, then add code required in separate commits. Then even if code needs the version to be bumped then when the client installs the tagged release, this happens. Thus leaving only devs to cope, which they can by down then upgrading.

@rogiervandongen
Copy link
Author

@gjb2048
Changes made.
Moodle's coding standards become more rediculous with every day passing. World uses PSR standards, moodle decides differently. Blank spaces, new lines... yada yada.
Some things are caused by auto formatting btw (such as "double indentations").

If a database wouldn't even be able to use the most basic SQL definitions, they cannot realistically be considered a usable database. This goes for DISTINCT (which is heavily used in Moodle's core), MIN/MAX functions, etc etc. So yeah, they're supported. By every database Moodle supports (which aren't that many).

Version bump removed.

Last but not least, added "global $DB" in vsf_after_restore_course_numsections() as it was missing.

@gjb2048
Copy link
Collaborator

gjb2048 commented Jul 24, 2024

@rogiervandongen Thanks, but where is the updated commit please? Fair enough with the SQL reply, I just did have to ask the question. And totally with the coding standards, drives me nuts some days!

@rogiervandongen
Copy link
Author

@gjb2048
My bad! I'm still getting used to the renewed interfacing of gitkraken.
If I'm not mistaken the 2nd commit should now be synced to the PR.
Cheers :)

Frankly, I've never seen that many non-sensical coding standards which the company that defines them is the exact same company that circumvents nearly every one of them 😂 "The joys of Moodle" (one of the worst to me is forbidding protected variables that are "underscore prefixed". The so called persistence model could be so much easier. From the moment I've started coding in PHP, which was somewhere in '07, all my business objects and models depended on "protected $_a", with getters and setters that then rely on magic __get, __set, __isset and __unset implementations that make for a much better to understand implementation. It also makes PHP's new Attributes implementation more than just easy to facilitate, aside from the fact actually implementing any logic using those attributes is terribly slow, unfortunately).
Anyway, those are not really discussions to be held here in a github repository ;)

@gjb2048 gjb2048 merged commit 2c9c69c into Lesterhuis-Training-en-Consultancy:master Jul 24, 2024
2 checks passed
@gjb2048
Copy link
Collaborator

gjb2048 commented Jul 24, 2024

@rogiervandongen Thanks, merged, the actual 'release' in version.php does need to go back, but I can do that as it seems I also have some code checker things to do on my code! Grrr! And, yeah with coding standards, nuff said!

gjb2048 added a commit that referenced this pull request Jul 24, 2024
gjb2048 pushed a commit that referenced this pull request Jul 25, 2024
gjb2048 pushed a commit that referenced this pull request Jul 25, 2024
gjb2048 pushed a commit that referenced this pull request Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants