Ejemplo n.º 1
0
 /**
  * Return cached backup id's
  *
  * @param int $restoreid id of backup
  * @param string $itemname name of the item
  * @param int $itemid id of item
  * @return array backup id's
  * @todo MDL-25290 replace static backupids* with MUC code
  */
 protected static function get_backup_ids_cached($restoreid, $itemname, $itemid)
 {
     global $DB;
     $key = "{$itemid} {$itemname} {$restoreid}";
     // If record exists in cache then return.
     if (isset(self::$backupidsexist[$key]) && isset(self::$backupidscache[$key])) {
         // Return a copy of cached data, to avoid any alterations in cached data.
         return clone self::$backupidscache[$key];
     }
     // Clean cache, if it's full.
     if (self::$backupidscachesize <= 0) {
         // Remove some records, to keep memory in limit.
         self::$backupidscache = array_slice(self::$backupidscache, self::$backupidsslice, null, true);
         self::$backupidscachesize = self::$backupidscachesize + self::$backupidsslice;
     }
     if (self::$backupidsexistsize <= 0) {
         self::$backupidsexist = array_slice(self::$backupidsexist, self::$backupidsslice, null, true);
         self::$backupidsexistsize = self::$backupidsexistsize + self::$backupidsslice;
     }
     // Retrive record from database.
     $record = array('backupid' => $restoreid, 'itemname' => $itemname, 'itemid' => $itemid);
     if ($dbrec = $DB->get_record('backup_ids_temp', $record)) {
         self::$backupidsexist[$key] = $dbrec->id;
         self::$backupidscache[$key] = $dbrec;
         self::$backupidscachesize--;
         self::$backupidsexistsize--;
         return $dbrec;
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * Reset the ids caches completely
  *
  * Any destructive operation (partial delete, truncate, drop or recreate) performed
  * with the backup_ids table must cause the backup_ids caches to be
  * invalidated by calling this method. See MDL-33630.
  *
  * Note that right now, the only operation of that type is the recreation
  * (drop & restore) of the table that may happen once the prechecks have ended. All
  * the rest of operations are always routed via {@link set_backup_ids_record()}, 1 by 1,
  * keeping the caches on sync.
  *
  * @todo MDL-25290 static should be replaced with MUC code.
  */
 public static function reset_backup_ids_cached()
 {
     // Reset the ids cache.
     $cachetoadd = count(self::$backupidscache);
     self::$backupidscache = array();
     self::$backupidscachesize = self::$backupidscachesize + $cachetoadd;
     // Reset the exists cache.
     $existstoadd = count(self::$backupidsexist);
     self::$backupidsexist = array();
     self::$backupidsexistsize = self::$backupidsexistsize + $existstoadd;
 }