The first thing we are going to look at is update hooks, revisiting our previous Sports module created in Chapter 8, The Database API. We will focus on the &$sandbox parameter we didn't use then. The goal is to run an update on each of our records in the players table and mark them as retired. The point is to illustrate how we can process each of these records one at a time in individual requests to prevent a PHP timeout. This is handy in case we have many records.
So to get us going, here is all the code, and we'll see right after what everything means:
/** * Update all the players to mark them as retired. */ function sports_update_8002(&$sandbox) { $database = \Drupal::database(); if (empty($sandbox)) { $results = $database->query("SELECT id FROM {players}")->fetchAllAssoc('id'); ...