/** * Обновление движка и шестерёнок */ public function admin_update() { $major = 0; $show_main = TRUE; switch ($this->input->get('action')) { case 'check': $check_url = 'https://github.com/codemotion/cogear2/tags'; $data = file_get_contents($check_url); preg_match_all('#/codemotion/cogear2/archive/v(.+?)\\.zip#', $data, $matches); for ($i = 0; $i < sizeof($matches[0]); $i++) { if (version_compare($matches[1][$i], $major) == 1) { $major = $matches[1][$i]; } } $this->set('admin.update.lastcheck', time()); $this->set('admin.update.repo.major', $major); break; case 'update_core': $version = config('admin.update.repo.major'); if (version_compare($version, COGEAR) == 1) { $link = 'https://github.com/codemotion/cogear2/archive/v' . $version . '.zip'; echo t('Загружаю архив с новой версией по адресу <i>%s</i>…', $link) . '<br/>'; if ($source = file_get_contents($link)) { $archive = TEMP . DS . 'v' . $version . '.zip'; file_put_contents($archive, $source); echo t('Архив загружен. Распаковываю…') . '<br/>'; $zip = new Zip($archive); $folder_index = $zip->statIndex(0); $folder = $folder_index['name']; $zip->extract(TEMP . DS); echo t('Архив распакован. Обновляю сайт…') . '<br/>'; $update_root = TEMP . DS . $folder; $this->update_files($update_root, ROOT); $show_main = FALSE; } else { echo t('Не удалось загрузить архив с системой!'); } } else { echo t('Версия системы в репозитории не превышает версию установленной системы.'); } echo '<p><a href="' . l('/admin/update') . '" class="btn">' . icon('arrow-left') . ' ' . t('Вернуться') . '</a>'; break; } $show_main && template('Admin/templates/update/main')->show(); }