/** * When a new release is activated, automatically archive the old releases. * * @internal * * @since 1.0 * * @param Release $release */ function archive_old_releases_on_new_activation(Release $release) { // we are paginating the number of releases we want to keep, and start on page 2 to get all that don't match // we don't need to calculate the number of total rows because we don't need the pagination, just the limit $releases = itelic_get_releases(array('items_per_page' => itelic_keep_last_n_releases($release->get_product()), 'page' => 2, 'status' => Release::STATUS_ACTIVE, 'product' => $release->get_product()->ID, 'order' => array('start_date' => 'DESC'))); foreach ($releases as $release) { $release->archive(); } }