destinations.inc 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. <?php
  2. /**
  3. * @file
  4. * All of the destination handling code needed for Backup and Migrate.
  5. */
  6. backup_migrate_include('crud', 'locations');
  7. /**
  8. * Get the available destination types.
  9. */
  10. function backup_migrate_get_destination_subtypes() {
  11. return backup_migrate_crud_subtypes('destination');
  12. }
  13. /**
  14. * Implementation of hook_backup_migrate_destination_subtypes().
  15. *
  16. * Get the built in Backup and Migrate destination types.
  17. */
  18. function backup_migrate_backup_migrate_destination_subtypes() {
  19. $out = array();
  20. if (variable_get('backup_migrate_allow_backup_to_file', TRUE)) {
  21. $out += array(
  22. 'file' => array(
  23. 'description' => t('Save the backup files to any directory on this server which the web-server can write to.'),
  24. 'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.file.inc',
  25. 'class' => 'backup_migrate_destination_files',
  26. 'type_name' => t('Server Directory'),
  27. 'local' => TRUE,
  28. 'can_create' => TRUE,
  29. ),
  30. 'file_manual' => array(
  31. 'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.file.inc',
  32. 'type_name' => t('Server Directory'),
  33. 'class' => 'backup_migrate_destination_files_manual',
  34. ),
  35. 'file_scheduled' => array(
  36. 'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.file.inc',
  37. 'type_name' => t('Server Directory'),
  38. 'class' => 'backup_migrate_destination_files_scheduled',
  39. ),
  40. );
  41. }
  42. $out += array(
  43. 'browser_download' => array(
  44. 'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.browser.inc',
  45. 'class' => 'backup_migrate_destination_browser_download',
  46. ),
  47. 'browser_upload' => array(
  48. 'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.browser.inc',
  49. 'class' => 'backup_migrate_destination_browser_upload',
  50. ),
  51. 'nodesquirrel' => array(
  52. 'description' => t('Save the backup files to the NodeSquirrel.com backup service.'),
  53. 'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.nodesquirrel.inc',
  54. 'class' => 'backup_migrate_destination_nodesquirrel',
  55. 'type_name' => t('NodeSquirrel.com'),
  56. 'can_create' => TRUE,
  57. 'remote' => TRUE,
  58. ),
  59. 'ftp' => array(
  60. 'description' => t('Save the backup files to any a directory on an FTP server.'),
  61. 'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.ftp.inc',
  62. 'class' => 'backup_migrate_destination_ftp',
  63. 'type_name' => t('FTP Directory'),
  64. 'can_create' => TRUE,
  65. 'remote' => TRUE,
  66. ),
  67. 's3' => array(
  68. 'description' => t('Save the backup files to a bucket on your !link.', array('!link' => l(t('Amazon S3 account'), 'http://aws.amazon.com/s3/'))),
  69. 'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.s3.inc',
  70. 'class' => 'backup_migrate_destination_s3',
  71. 'type_name' => t('Amazon S3 Bucket'),
  72. 'can_create' => TRUE,
  73. 'remote' => TRUE,
  74. ),
  75. 'email' => array(
  76. 'type_name' => t('Email'),
  77. 'description' => t('Send the backup as an email attachment to the specified email address.'),
  78. 'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.email.inc',
  79. 'class' => 'backup_migrate_destination_email',
  80. 'can_create' => TRUE,
  81. 'remote' => TRUE,
  82. ),
  83. );
  84. return $out;
  85. }
  86. /**
  87. * Implementation of hook_backup_migrate_destinations().
  88. *
  89. * Get the built in backup destinations and those in the db.
  90. */
  91. function backup_migrate_backup_migrate_destinations() {
  92. $out = array();
  93. // Add the default, out of the box destinations for new users.
  94. if (variable_get('backup_migrate_allow_backup_to_file', TRUE)) {
  95. if (variable_get('file_private_path', FALSE)) {
  96. $out['manual'] = backup_migrate_create_destination('file_manual', array('machine_name' => 'manual'));
  97. $out['scheduled'] = backup_migrate_create_destination('file_scheduled', array('machine_name' => 'scheduled'));
  98. }
  99. else {
  100. _backup_migrate_message('You must specify a private file system path in the !settings to backup to the server.', array('!settings' => l(t('file system settings'), 'admin/config/media/file-system')), 'warning');
  101. }
  102. }
  103. // Add the browser destination for downloading to the desktop.
  104. if (variable_get('backup_migrate_allow_backup_to_download', TRUE)) {
  105. $out['download'] = backup_migrate_create_destination('browser_download');
  106. }
  107. $out['upload'] = backup_migrate_create_destination('browser_upload');
  108. // Expose the configured databases as sources.
  109. backup_migrate_include('filters');
  110. $out += backup_migrate_filters_invoke_all('destinations');
  111. return $out;
  112. }
  113. /**
  114. * Get all the available backup destination.
  115. *
  116. * @param $op
  117. * The operation which will be performed on the destination. Hooks can use this
  118. * to return only those destinations appropriate for the given op.
  119. * Options include:
  120. * 'manual backup' - destinations available for manual backup
  121. * 'scheduled backup' - destinations available for schedules backup
  122. * 'list files' - destinations whose backup files can be listed
  123. * 'restore' - destinations whose files can be restored from
  124. * 'all' - all available destinations should be returned
  125. */
  126. function backup_migrate_get_destinations($op = 'all') {
  127. static $destinations = NULL;
  128. // Get the list of destinations and cache them locally.
  129. if ($destinations === NULL) {
  130. $destinations = backup_migrate_crud_get_items('destination');
  131. }
  132. // Return all if that's what was asked for.
  133. if ($op == 'all') {
  134. return $destinations;
  135. }
  136. // Return only those destinations which support the given op.
  137. $out = array();
  138. foreach ($destinations as $key => $destination) {
  139. if ($destination->op($op)) {
  140. $out[$key] = $destination;
  141. }
  142. }
  143. return $out;
  144. }
  145. /**
  146. * Get the destination of the given id.
  147. */
  148. function backup_migrate_get_destination($id) {
  149. $destinations = backup_migrate_get_destinations('all');
  150. return empty($destinations[$id]) ? NULL : $destinations[$id];
  151. }
  152. /**
  153. * Create a destination object of the given type with the given params.
  154. */
  155. function backup_migrate_create_destination($destination_type, $params = array()) {
  156. $params['subtype'] = $destination_type;
  157. return backup_migrate_crud_create_item('destination', $params);
  158. }
  159. /**
  160. * Load a file from a destination and return the file info.
  161. */
  162. function backup_migrate_destination_get_file($destination_id, $file_id) {
  163. if ($destination = backup_migrate_get_destination($destination_id)) {
  164. return $destination->load_file($file_id);
  165. }
  166. return NULL;
  167. }
  168. /**
  169. * Load a file from a destination and return the file info.
  170. */
  171. function backup_migrate_destination_get_latest_file($destination_id) {
  172. $out = NULL;
  173. if ($destination = backup_migrate_get_destination($destination_id)) {
  174. $files = $destination->list_files();
  175. $max = 0;
  176. foreach ((array)$files as $file) {
  177. $info = $file->info();
  178. // If there's a datestamp, it should override the filetime as it's probably more reliable.
  179. $time = !empty($info['datestamp']) ? $info['datestamp'] : $info['filetime'];
  180. if ($time > $max) {
  181. $max = $time;
  182. $out = $file;
  183. }
  184. }
  185. }
  186. return $out;
  187. }
  188. /**
  189. * Check if a file exists in the given destination.
  190. */
  191. function backup_migrate_destination_file_exists($destination_id, $file_id) {
  192. if ($destination = backup_migrate_get_destination($destination_id)) {
  193. return $destination->file_exists($file_id);
  194. }
  195. return NULL;
  196. }
  197. /**
  198. * Send a file to the destination specified by the settings array.
  199. */
  200. function backup_migrate_destination_confirm_destination(&$settings) {
  201. if ($destinations = $settings->get_destinations()) {
  202. foreach ($destinations as $key => $destination) {
  203. // Check that the destination is ready to go.
  204. if (!$destination->confirm_destination()) {
  205. unset($destinations[$key]);
  206. }
  207. }
  208. }
  209. $settings->destinations = $destinations;
  210. return count($destinations);
  211. }
  212. /**
  213. * Send a file to the destination specified by the settings array.
  214. */
  215. function backup_migrate_destination_save_file($file, &$settings) {
  216. $saved_to = array();
  217. if ($destinations = $settings->get_destinations()) {
  218. foreach ($destinations as $destination) {
  219. // Make sure the file only gets saved to each destination once.
  220. $id = $destination->get('id');
  221. if (!in_array($id, $saved_to)) {
  222. if ($destination->save_file($file, $settings)) {
  223. $saved_to[] = $id;
  224. }
  225. }
  226. }
  227. }
  228. return $saved_to ? $file : FALSE;
  229. }
  230. /**
  231. * Delete a file in the given destination.
  232. */
  233. function backup_migrate_destination_delete_file($destination_id, $file_id) {
  234. if ($destination = backup_migrate_get_destination($destination_id)) {
  235. return $destination->delete_file($file_id);
  236. }
  237. }
  238. /**
  239. * Get the action links for a file on a given destination.
  240. */
  241. function _backup_migrate_destination_get_file_links($destination_id, $file_id) {
  242. $out = array();
  243. if ($destination = backup_migrate_get_destination($destination_id)) {
  244. $out = $destination->get_file_links($file_id);
  245. }
  246. return $out;
  247. }
  248. /* UI Menu Callbacks */
  249. /**
  250. * List the backup files in the given destination.
  251. */
  252. function backup_migrate_ui_destination_display_files($destination_id = NULL) {
  253. drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css');
  254. $rows = $sort = array();
  255. if ($destination = backup_migrate_get_destination($destination_id)) {
  256. drupal_set_title(t('@title Files', array('@title' => $destination->get_name())));
  257. return _backup_migrate_ui_destination_display_files($destination, 20, TRUE);
  258. }
  259. drupal_goto(BACKUP_MIGRATE_MENU_PATH . "/destination");
  260. }
  261. /**
  262. * List the backup files in the given destination.
  263. */
  264. function _backup_migrate_ui_destination_display_files($destination = NULL, $limit = NULL, $show_pager = FALSE) {
  265. if ($destination) {
  266. // Refresh the file listing cache if requested.
  267. if (isset($_GET['refresh'])) {
  268. $destination->file_cache_clear();
  269. drupal_goto($_GET['q']);
  270. }
  271. $files = $destination->list_files();
  272. $fetch = $out = '';
  273. // Get the fetch link.
  274. if ($destination->cache_files && $destination->fetch_time) {
  275. $fetch = '<div class="description">'. t('This listing was fetched !time ago. !refresh', array('!time' => format_interval(time() - $destination->fetch_time, 1), '!refresh' => l(t('fetch now'), $_GET['q'], array('query' => array('refresh' => 'true'))))) .'</div>';
  276. }
  277. $out .= $fetch;
  278. $out .= _backup_migrate_ui_destination_display_file_list($files, array('limit' => 20, 'pager' => TRUE));
  279. $out .= $fetch;
  280. return $out;
  281. }
  282. }
  283. /**
  284. * List the backup files in the given destination.
  285. */
  286. function _backup_migrate_ui_destination_display_file_list($files, $options = array()) {
  287. drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css');
  288. // Set soem default options
  289. $options += array(
  290. 'pager' => TRUE,
  291. 'more' => FALSE,
  292. 'operations' => TRUE,
  293. 'limit' => NULL,
  294. 'form_elements' => NULL,
  295. );
  296. $rows = $sort = array();
  297. if ($files) {
  298. $headers = array(
  299. array('data' => 'Filename', 'field' => 'filename'),
  300. array('data' => 'Created', 'field' => 'filetime', 'sort' => 'desc'),
  301. array('data' => 'Size', 'field' => 'filesize'),
  302. );
  303. if ($options['operations']) {
  304. $headers[] = array('data' => 'Operations');
  305. }
  306. if ($options['form_elements']) {
  307. array_unshift($headers, '');
  308. }
  309. $sort_order = tablesort_get_order($headers);
  310. $sort_key = $sort_order['sql'] ? $sort_order['sql'] : 'filetime';
  311. $sort_dir = tablesort_get_sort($headers) == 'desc' ? SORT_DESC : SORT_ASC;
  312. $i = 0;
  313. foreach ((array)$files as $id => $file) {
  314. $info = $file->info();
  315. // If there's a datestamp, it should override the filetime as it's probably more reliable.
  316. $info['filetime'] = !empty($info['datestamp']) ? $info['datestamp'] : $info['filetime'];
  317. $description = '';
  318. // Add the description as a new row.
  319. if (!empty($info['description'])) {
  320. $description .= ' <div title="' . check_plain($info['description']) . '" class="backup-migrate-description">' . check_plain($info['description']) . '</div>';
  321. }
  322. // Add the backup source.
  323. if (!empty($info['bam_sourcename'])) {
  324. $description .= ' <div title="'. check_plain($info['bam_sourcename']) .'" class="backup-migrate-tags"><span class="backup-migrate-label">'. t('Source:') .' </span>' . check_plain($info['bam_sourcename']) . '</div>';
  325. }
  326. // Add the tags as a new row.
  327. if (!empty($info['tags'])) {
  328. $tags = check_plain(implode(', ', (array)$info['tags']));
  329. $description .= ' <div title="' . $tags . '" class="backup-migrate-tags"><span class="backup-migrate-label">' . t('Tags:') . ' </span>' . $tags . '</div>';
  330. }
  331. // Add the other info.
  332. if (!empty($info['bam_other_safe'])) {
  333. foreach ($info['bam_other_safe'] as $label => $data) {
  334. $description .= ' <div class="backup-migrate-tags"><span class="backup-migrate-label">' . $label . ' </span>' . $data . '</div>';
  335. }
  336. }
  337. // Show only files that can be restored from.
  338. $sort[] = $info[$sort_key];
  339. $row = array(
  340. check_plain($info['filename']) . $description,
  341. t('!time ago', array('!time' => format_interval(time() - $info['filetime'], 2))) . '<div class="backup-migrate-date">' . format_date($info['filetime'], 'small') . '</div>',
  342. format_size($info['filesize']),
  343. );
  344. if ($options['operations']) {
  345. $row[] = array('data' => implode(' &nbsp; ', $file->destination->get_file_links($file->file_id())), 'class' => 'backup-migrate-actions');
  346. }
  347. if (isset($options['form_elements'][$id])) {
  348. array_unshift($row, $options['form_elements'][$id]);
  349. }
  350. $rows[] = $row;
  351. }
  352. array_multisort($sort, $sort_dir, $rows);
  353. // Show only some of them if it's limited.
  354. $showing = $pager = $more = '';
  355. if ($options['limit']) {
  356. $limit = $options['limit'];
  357. $total = count($rows);
  358. $end = $limit;
  359. $start = 0;
  360. if ($options['pager']) {
  361. $page = isset($_GET['page']) ? $_GET['page'] : '';
  362. $start = $page * $limit;
  363. $element = 0;
  364. $GLOBALS['pager_total'][$element] = ceil($total / $limit);
  365. $GLOBALS['pager_page_array'][$element] = $page;
  366. $tags = array(
  367. t('« newest'),
  368. t('« newer'),
  369. '',
  370. t('older »'),
  371. t('oldest »'),
  372. );
  373. $pager = theme('pager', $tags, $limit, $element, array(), ceil($total/$limit));
  374. $end = min($total - 1, $start + $limit);
  375. }
  376. if ($total > $limit && $options['more']) {
  377. $more = ' ' . l(t('view all'), $options['more']);
  378. }
  379. $showing = t('Showing @start to @end of @total files.', array('@start' => $start + 1, '@end' => $end + 1, '@total' => $total));
  380. // Limit the number of rows shown.
  381. $rows = array_slice($rows, $start, $limit, TRUE);
  382. }
  383. $out = theme("table", array('header' => $headers, 'rows' => $rows, 'class' => 'backup-migrate-listing backup-migrate-listing-files'));
  384. $out .= $showing;
  385. $out .= $pager;
  386. $out .= $more;
  387. }
  388. else {
  389. $out = t('There are no backup files to display.');
  390. }
  391. return $out;
  392. }
  393. /**
  394. * List the backup files in the given destination.
  395. */
  396. function _backup_migrate_ui_destination_display_file_list_options($files, $limit = NULL) {
  397. drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css');
  398. $rows = $sort = array();
  399. if ($files) {
  400. $headers = array(
  401. '',
  402. array('data' => 'Filename', 'field' => 'filename'),
  403. array('data' => 'Created', 'field' => 'filetime', 'sort' => 'desc'),
  404. array('data' => 'Size', 'field' => 'filesize'),
  405. );
  406. $sort_order = tablesort_get_order($headers);
  407. $sort_key = $sort_order['sql'] ? $sort_order['sql'] : 'filetime';
  408. $sort_dir = tablesort_get_sort($headers) == 'desc' ? SORT_DESC : SORT_ASC;
  409. $i = 0;
  410. foreach ((array)$files as $file) {
  411. $info = $file->info();
  412. // If there's a datestamp, it should override the filetime as it's probably more reliable.
  413. $info['filetime'] = !empty($info['datestamp']) ? $info['datestamp'] : $info['filetime'];
  414. $description = '';
  415. // Add the description as a new row.
  416. if (!empty($info['description'])) {
  417. $description .= ' <div title="' . check_plain($info['description']) . '" class="backup-migrate-description">' . check_plain($info['description']) . '</div>';
  418. }
  419. // Add the backup source.
  420. if (!empty($info['bam_sourcename'])) {
  421. $description .= ' <div title="'. check_plain($info['bam_sourcename']) .'" class="backup-migrate-tags"><span class="backup-migrate-label">'. t('Source:') .' </span>' . check_plain($info['bam_sourcename']) . '</div>';
  422. }
  423. // Add the tags as a new row.
  424. if (!empty($info['tags'])) {
  425. $tags = check_plain(implode(', ', (array)$info['tags']));
  426. $description .= ' <div title="' . $tags . '" class="backup-migrate-tags"><span class="backup-migrate-label">' . t('Tags:') . ' </span>' . $tags . '</div>';
  427. }
  428. // Add the other info.
  429. if (!empty($info['bam_other_safe'])) {
  430. foreach ($info['bam_other_safe'] as $label => $data) {
  431. $description .= ' <div class="backup-migrate-tags"><span class="backup-migrate-label">' . $label . ' </span>' . $data . '</div>';
  432. }
  433. }
  434. // Show only files that can be restored from.
  435. $sort[] = $info[$sort_key];
  436. $rows[] = array(
  437. 'radio',
  438. check_plain($info['filename']) . $description,
  439. t('!time ago', array('!time' => format_interval(time() - $info['filetime'], 2))) . '<div class="backup-migrate-date">' . format_date($info['filetime'], 'small') . '</div>',
  440. format_size($info['filesize']),
  441. );
  442. }
  443. array_multisort($sort, $sort_dir, $rows);
  444. // Show only some of them if it's limited.
  445. $showing = $pager = '';
  446. if ($limit) {
  447. $total = count($rows);
  448. $end = $limit;
  449. $start = 0;
  450. $showing = t('Showing @start to @end of @total files.', array('@start' => $start + 1, '@end' => $end + 1, '@total' => $total));
  451. // Limit the number of rows shown.
  452. $rows = array_slice($rows, $start, $limit, TRUE);
  453. }
  454. $out = theme("table", array('header' => $headers, 'rows' => $rows, 'class' => 'backup-migrate-listing backup-migrate-listing-files'));
  455. $out .= $showing;
  456. }
  457. else {
  458. $out = t('There are no backup files to display.');
  459. }
  460. return $out;
  461. }
  462. /**
  463. * Download a file to the browser.
  464. */
  465. function backup_migrate_ui_destination_download_file($destination_id = NULL, $file_id = NULL) {
  466. if ($file = backup_migrate_destination_get_file($destination_id, $file_id)) {
  467. backup_migrate_include('files');
  468. $file->transfer();
  469. }
  470. drupal_goto(BACKUP_MIGRATE_MENU_PATH);
  471. }
  472. /**
  473. * Restore a backup file from a destination.
  474. */
  475. function backup_migrate_ui_destination_restore_file($destination_id = NULL, $file_id = NULL) {
  476. if (backup_migrate_destination_file_exists($destination_id, $file_id)) {
  477. return drupal_get_form('backup_migrate_ui_destination_restore_file_confirm', $destination_id, $file_id);
  478. }
  479. _backup_migrate_message('Cannot restore from the the file: %file_id because it does not exist.', array('%file_id' => $file_id), 'error');
  480. if ($destination_id && user_access('access backup files')) {
  481. drupal_goto(BACKUP_MIGRATE_MENU_PATH . '/destination/list/files/' . $destination_id);
  482. }
  483. drupal_goto(BACKUP_MIGRATE_MENU_PATH);
  484. }
  485. /**
  486. * Ask confirmation for file restore.
  487. */
  488. function backup_migrate_ui_destination_restore_file_confirm($form, &$form_state, $destination_id, $file_id) {
  489. $sources = _backup_migrate_get_source_form_item_options();
  490. if (count($sources) > 1) {
  491. $form['source_id'] = array(
  492. "#type" => "select",
  493. "#title" => t("Restore to"),
  494. "#options" => $sources,
  495. "#description" => t("Choose the database to restore to. Any database destinations you have created and any databases specified in your settings.php can be restored to."),
  496. "#default_value" => 'db',
  497. );
  498. }
  499. else {
  500. $form['source_id'] = array(
  501. "#type" => "value",
  502. "#value" => 'db',
  503. );
  504. }
  505. $form['destination_id'] = array('#type' => 'value', '#value' => $destination_id);
  506. $form['file_id'] = array('#type' => 'value', '#value' => $file_id);
  507. $form = confirm_form($form, t('Are you sure you want to restore the database?'), BACKUP_MIGRATE_MENU_PATH . "/destination/list/files/". $destination_id, t('Are you sure you want to restore the database from the backup file %file_id? This will delete some or all of your data and cannot be undone. <strong>Always test your backups on a non-production server!</strong>', array('%file_id' => $file_id)), t('Restore'), t('Cancel'));
  508. drupal_set_message(t('Restoring will delete some or all of your data and cannot be undone. <strong>Always test your backups on a non-production server!</strong>'), 'warning', FALSE);
  509. $form = array_merge_recursive($form, backup_migrate_filters_settings_form(backup_migrate_filters_settings_default('restore'), 'restore'));
  510. $form['actions']['#weight'] = 100;
  511. // Add the advanced fieldset if there are any fields in it.
  512. if (@$form['advanced']) {
  513. $form['advanced']['#type'] = 'fieldset';
  514. $form['advanced']['#title'] = t('Advanced Options');
  515. $form['advanced']['#collapsed'] = true;
  516. $form['advanced']['#collapsible'] = true;
  517. }
  518. return $form;
  519. }
  520. /**
  521. * Do the file restore.
  522. */
  523. function backup_migrate_ui_destination_restore_file_confirm_submit($form, &$form_state) {
  524. $destination_id = $form_state['values']['destination_id'];
  525. $file_id = $form_state['values']['file_id'];
  526. if ($destination_id && $file_id) {
  527. backup_migrate_perform_restore($destination_id, $file_id, $form_state['values']);
  528. }
  529. $redir = user_access('access backup files') ? BACKUP_MIGRATE_MENU_PATH . "/destination/list/files/". $destination_id : BACKUP_MIGRATE_MENU_PATH;
  530. $form_state['redirect'] = $redir;
  531. }
  532. /**
  533. * Menu callback to delete a file from a destination.
  534. */
  535. function backup_migrate_ui_destination_delete_file($destination_id = NULL, $file_id = NULL) {
  536. if (backup_migrate_destination_file_exists($destination_id, $file_id)) {
  537. return drupal_get_form('backup_migrate_ui_destination_delete_file_confirm', $destination_id, $file_id);
  538. }
  539. _backup_migrate_message('Cannot delete the file: %file_id because it does not exist.', array('%file_id' => $file_id), 'error');
  540. if ($destination_id && user_access('access backup files')) {
  541. drupal_goto(BACKUP_MIGRATE_MENU_PATH .'/destination/list/files/' . $destination_id);
  542. }
  543. drupal_goto(BACKUP_MIGRATE_MENU_PATH);
  544. }
  545. /**
  546. * Ask confirmation for file deletion.
  547. */
  548. function backup_migrate_ui_destination_delete_file_confirm($form, &$form_state, $destination_id, $file_id) {
  549. $form['destination_id'] = array('#type' => 'value', '#value' => $destination_id);
  550. $form['file_id'] = array('#type' => 'value', '#value' => $file_id);
  551. return confirm_form($form, t('Are you sure you want to delete the backup file?'), BACKUP_MIGRATE_MENU_PATH . '/destination/list/files/'. $destination_id, t('Are you sure you want to delete the backup file %file_id? <strong>This action cannot be undone.</strong>', array('%file_id' => $file_id)), t('Delete'), t('Cancel'));
  552. }
  553. /**
  554. * Delete confirmed, perform the delete.
  555. */
  556. function backup_migrate_ui_destination_delete_file_confirm_submit($form, &$form_state) {
  557. if (user_access('delete backup files')) {
  558. $destination_id = $form_state['values']['destination_id'];
  559. $file_id = $form_state['values']['file_id'];
  560. backup_migrate_destination_delete_file($destination_id, $file_id);
  561. _backup_migrate_message('Database backup file deleted: %file_id', array('%file_id' => $file_id));
  562. }
  563. $form_state['redirect'] = user_access('access backup files') ? BACKUP_MIGRATE_MENU_PATH . "/destination/list/files/". $destination_id : BACKUP_MIGRATE_MENU_PATH;
  564. }
  565. /* Utilities */
  566. /**
  567. * Get pulldown to select existing source options.
  568. */
  569. function _backup_migrate_get_destination_pulldown($op, $destination_id = NULL, $copy_destination_id = NULL) {
  570. drupal_add_js(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.js');
  571. $destinations = _backup_migrate_get_destination_form_item_options($op);
  572. $form = array(
  573. '#element_validate' => array('_backup_migrate_destination_pulldown_validate'),
  574. '#after_build' => array('_backup_migrate_process_destination_pulldown'),
  575. );
  576. $form['destination_id'] = array(
  577. '#type' => 'select',
  578. '#title' => t('Backup Destination'),
  579. '#options' => $destinations,
  580. '#default_value' => $destination_id,
  581. //'#process' => array('_backup_migrate_process_destination_pulldown'),
  582. );
  583. if (user_access('administer backup and migrate')) {
  584. $form['destination_id']['#description'] = l(t("Create new destination"), BACKUP_MIGRATE_MENU_PATH . "/destination/add");
  585. }
  586. $form['copy'] = array(
  587. '#type' => 'checkbox',
  588. '#title' => '<span class="backup-migrate-destination-copy-label">' . t('Save a copy to a second destination') . '</span>',
  589. '#default_value' => !empty($copy_destination_id),
  590. );
  591. $form['copy_destination'] = array(
  592. '#type' => 'backup_migrate_dependent',
  593. '#dependencies' => array(
  594. 'copy' => TRUE,
  595. ),
  596. );
  597. $form['copy_destination']['copy_destination_id'] = array(
  598. '#type' => 'select',
  599. '#title' => t('Second Backup Destination'),
  600. '#options' => $destinations,
  601. '#default_value' => $copy_destination_id,
  602. );
  603. return $form;
  604. }
  605. /**
  606. * Return the destination pulldown with an option to save a second copy.
  607. */
  608. function _backup_migrate_process_destination_pulldown($element) {
  609. $id = $element['destination_id']['#id'];
  610. $settings = array(
  611. 'backup_migrate' => array(
  612. 'destination_selectors' => array(
  613. $id => array(
  614. 'destination_selector' => $id,
  615. 'copy_destination_selector' => $element['copy_destination']['copy_destination_id']['#id'],
  616. 'copy' => $element['copy']['#id'],
  617. 'labels' => array(
  618. t('Local') => t('Save an offsite copy to'),
  619. t('Offsite') => t('Save a local copy to'),
  620. )
  621. )
  622. )
  623. )
  624. );
  625. drupal_add_js($settings, 'setting');
  626. return $element;
  627. }
  628. /**
  629. * Validate the destination and second destination widget.
  630. */
  631. function _backup_migrate_destination_pulldown_validate($element, &$form_state, $form) {
  632. if (empty($element['copy']['#value']) || $element['copy_destination']['copy_destination_id']['#value'] == $element['destination_id']['#value']) {
  633. _backup_migrate_destination_pulldown_set_value($form_state['values'], $element['copy_destination']['copy_destination_id']['#parents'], '');
  634. }
  635. }
  636. /**
  637. * Set the value of a form field given it's parent array.
  638. */
  639. function _backup_migrate_destination_pulldown_set_value(&$values, $parents, $value) {
  640. $key = array_shift($parents);
  641. if (empty($parents)) {
  642. $values[$key] = $value;
  643. }
  644. else {
  645. _backup_migrate_destination_pulldown_set_value($values[$key], $parents, $value);
  646. }
  647. }
  648. /**
  649. * Get the destination options as an options array for a form item.
  650. */
  651. function _backup_migrate_get_destination_form_item_options($op) {
  652. $remote = $local = array();
  653. foreach (backup_migrate_get_destinations($op) as $key => $destination) {
  654. if ($destination->op('remote backup')) {
  655. $remote[$key] = $destination->get_name();
  656. }
  657. else {
  658. $local[$key] = $destination->get_name();
  659. }
  660. }
  661. $out = array();
  662. if ($remote && $local) {
  663. $out = array(
  664. t('Local') => $local,
  665. t('Offsite') => $remote,
  666. );
  667. }
  668. else {
  669. $out = $remote + $local;
  670. }
  671. return $out;
  672. }
  673. /**
  674. * A base class for creating destinations.
  675. */
  676. class backup_migrate_destination extends backup_migrate_location {
  677. var $db_table = "backup_migrate_destinations";
  678. var $type_name = "destination";
  679. var $default_values = array('settings' => array());
  680. var $singular = 'destination';
  681. var $plural = 'destinations';
  682. var $title_plural = 'Destinations';
  683. var $title_singular = 'Destination';
  684. var $cache_files = FALSE;
  685. var $fetch_time = NULL;
  686. var $cache_expire = 86400; // 24 hours
  687. var $weight = 0;
  688. var $destination_type = "";
  689. var $supported_ops = array();
  690. /**
  691. * This function is not supposed to be called. It is just here to help the po extractor out.
  692. */
  693. function strings() {
  694. // Help the pot extractor find these strings.
  695. t('Destination');
  696. t('Destinations');
  697. t('destinations');
  698. t('destination');
  699. }
  700. /**
  701. * Save the given file to the destination.
  702. */
  703. function save_file($file, $settings) {
  704. $this->file_cache_clear();
  705. // Save the file metadata if the destination supports it.
  706. $this->save_file_info($file, $settings);
  707. return $this->_save_file($file, $settings);
  708. }
  709. /**
  710. * Save the given file to the destination.
  711. */
  712. function _save_file($file, $settings) {
  713. // This must be overriden.
  714. return $file;
  715. }
  716. /**
  717. * Save the file metadata
  718. */
  719. function save_file_info($file, $settings) {
  720. $info = $this->create_info_file($file);
  721. // Save the info file and the actual file.
  722. return $this->_save_file($info, $settings);
  723. }
  724. /**
  725. * Load the file with the given destination specific id and return as a backup_file object.
  726. */
  727. function load_file($file_id) {
  728. // This must be overriden.
  729. return NULL;
  730. }
  731. /**
  732. * Check if a file exists in the given destination.
  733. */
  734. function file_exists($file_id) {
  735. // Check if the file exists in the list of available files. Actual destination types may have more efficient ways of doing this.
  736. $files = $this->list_files();
  737. return isset($files[$file_id]);
  738. }
  739. /**
  740. * List all the available files in the given destination with their destination specific id.
  741. */
  742. function list_files() {
  743. $files = NULL;
  744. if ($this->cache_files) {
  745. $files = $this->file_cache_get();
  746. }
  747. if ($files === NULL) {
  748. $files = $this->_list_files();
  749. $files = $this->load_files_info($files);
  750. if ($this->cache_files) {
  751. $this->file_cache_set($files);
  752. }
  753. }
  754. $out = array();
  755. if (is_array($files)) {
  756. foreach ($files as $id => $file) {
  757. if ($file->is_recognized_type()) {
  758. $out[$id] = $file;
  759. $out[$id]->destination = &$this;
  760. }
  761. }
  762. }
  763. return $out;
  764. }
  765. /**
  766. * List all the available files in the given destination with their destination specific id.
  767. */
  768. function count_files() {
  769. return count($this->list_files());
  770. }
  771. /**
  772. * List all the available files in the given destination with their destination specific id.
  773. */
  774. function _list_files() {
  775. return array();
  776. }
  777. /**
  778. * Load up the file's metadata from the accompanying .info file if applicable.
  779. */
  780. function load_files_info($files) {
  781. foreach ($files as $key => $file) {
  782. // See if there is an info file with the same name as the backup.
  783. if (isset($files[$key . '.info'])) {
  784. $info_file = $this->load_file($files[$key . '.info']->file_id());
  785. $info = drupal_parse_info_file($info_file->filepath());
  786. // Allow the stored metadata to override the detected metadata.
  787. unset($info['filename']);
  788. $file->file_info = $info + $file->file_info;
  789. // Remove the metadata file from the list
  790. unset($files[$key . '.info']);
  791. }
  792. // Add destination specific info.
  793. $file->info_set('destination_id', $this->get('id'));
  794. $file->info_set('remote', $this->get('remote'));
  795. }
  796. return $files;
  797. }
  798. /**
  799. * Create an ini file and write the meta data.
  800. */
  801. function create_info_file($file) {
  802. $info = $this->_file_info_file($file);
  803. $data = _backup_migrate_array_to_ini($file->file_info);
  804. $info->put_contents($data);
  805. return $info;
  806. }
  807. /**
  808. * Create the info file object.
  809. */
  810. function _file_info_file($file) {
  811. $info = new backup_file(array('filename' => $this->_file_info_filename($file->file_id())));
  812. return $info;
  813. }
  814. /**
  815. * Determine the file name of the info file for a file.
  816. */
  817. function _file_info_filename($file_id) {
  818. return $file_id . '.info';
  819. }
  820. /**
  821. * Cache the file list.
  822. */
  823. function file_cache_set($files) {
  824. cache_set('backup_migrate_file_list:'. $this->get_id(), $files, 'cache', time() + $this->cache_expire);
  825. }
  826. /**
  827. * Retrieve the file list.
  828. */
  829. function file_cache_get() {
  830. backup_migrate_include('files');
  831. $cache = cache_get('backup_migrate_file_list:'. $this->get_id());
  832. if (!empty($cache->data) && $cache->created > (time() - $this->cache_expire)) {
  833. $this->fetch_time = $cache->created;
  834. return $cache->data;
  835. }
  836. $this->fetch_time = 0;
  837. return NULL;
  838. }
  839. /**
  840. * Retrieve the file list.
  841. */
  842. function file_cache_clear() {
  843. if ($this->cache_files) {
  844. $this->file_cache_set(NULL);
  845. }
  846. }
  847. /**
  848. * Delete the file with the given destination specific id.
  849. */
  850. function delete_file($file_id) {
  851. $this->file_cache_clear();
  852. $this->_delete_file($file_id);
  853. $this->_delete_file($this->_file_info_filename($file_id));
  854. }
  855. /**
  856. * Delete the file with the given destination specific id.
  857. */
  858. function _delete_file($file_id) {
  859. // This must be overriden.
  860. }
  861. /**
  862. * Get the edit form for the item.
  863. */
  864. function edit_form() {
  865. if (get_class($this) !== 'backup_migrate_destination') {
  866. $form = parent::edit_form();
  867. $form['subtype'] = array(
  868. "#type" => "value",
  869. "#default_value" => $this->get('subtype'),
  870. );
  871. }
  872. else {
  873. $types = backup_migrate_get_destination_subtypes();
  874. $items = array(
  875. 'remote' => array(
  876. 'title' => t('Offsite Destinations'),
  877. 'description' => t('For the highest level of protection, set up an offsite backup destination in a location separate from your website.'),
  878. 'items' => array(),
  879. ),
  880. 'local' => array(
  881. 'title' => t('Local Destinations'),
  882. 'description' => t('Local backups are quick and convenient but do not provide the additional safety of offsite backups.'),
  883. 'items' => array(),
  884. ),
  885. 'other' => array(
  886. 'title' => t('Other Destinations'),
  887. 'description' => t('These destinations have not been classified because they were created for Backup and Migrate version 2. They may not work correctly with this version.'),
  888. 'items' => array(),
  889. ),
  890. );
  891. // If no (valid) node type has been provided, display a node type overview.
  892. $path = $this->get_settings_path();
  893. foreach ($types as $key => $type) {
  894. if (@$type['can_create']) {
  895. $type_url_str = str_replace('_', '-', $key);
  896. $out = '<dt>'. l($type['type_name'], $path . "/add/$type_url_str", array('attributes' => array('title' => t('Add a new @s destination.', array('@s' => $type['type_name']))))) .'</dt>';
  897. $out .= '<dd>'. filter_xss_admin($type['description']) .'</dd>';
  898. if (!empty($type['local'])) {
  899. $items['local']['items'][] = $out;
  900. }
  901. if (!empty($type['remote'])) {
  902. $items['remote']['items'][] = $out;
  903. }
  904. if (empty($type['local']) && empty($type['remote'])) {
  905. $items['other']['items'][] = $out;
  906. }
  907. }
  908. }
  909. if (count($items['local']['items']) || count($items['remote']['items']) || count($items['other']['items'])) {
  910. $output = '<p>' . t('Choose the type of destination you would like to create:') . '</p>';
  911. foreach ($items as $group) {
  912. if (count($group['items'])) {
  913. $group['body'] = '<dl>'. implode('', $group['items']) .'</dl>';
  914. $output .= theme('backup_migrate_group', $group);
  915. }
  916. }
  917. }
  918. else {
  919. $output = t('No destination types available.');
  920. }
  921. $form['select_type'] = array(
  922. '#type' => 'markup',
  923. '#markup' => $output,
  924. );
  925. }
  926. return $form;
  927. }
  928. /**
  929. * Get the message to send to the user when confirming the deletion of the item.
  930. */
  931. function delete_confirm_message() {
  932. return t('Are you sure you want to delete the destination %name? Backup files already saved to this destination will not be deleted.', array('%name' => $this->get_name()));
  933. }
  934. /**
  935. * Get a boolean representing if the destination is remote or local.
  936. */
  937. function get_remote() {
  938. return $this->op('remote backup');
  939. }
  940. /**
  941. * Get the action links for a destination.
  942. */
  943. function get_action_links() {
  944. $out = parent::get_action_links();
  945. $item_id = $this->get_id();
  946. // Don't display the download/delete/restore ops if they are not available for this destination.
  947. if ($this->op('list files') && user_access("access backup files")) {
  948. $out = array('list files' => l(t("list files"), $this->get_settings_path() . '/list/files/'. $item_id)) + $out;
  949. }
  950. if (!$this->op('configure') || !user_access('administer backup and migrate')) {
  951. unset($out['edit']);
  952. }
  953. return $out;
  954. }
  955. /**
  956. * Get the action links for a file on a given destination.
  957. */
  958. function get_file_links($file_id) {
  959. $out = array();
  960. // Don't display the download/delete/restore ops if they are not available for this destination.
  961. $can_read = $this->can_read_file($file_id);
  962. $can_delete = $this->can_delete_file($file_id);
  963. $path = $this->get_settings_path();
  964. $destination_id = $this->get_id();
  965. if ($can_read && user_access("access backup files")) {
  966. $out[] = l(t("download"), $path . '/downloadfile/'. $destination_id .'/'. $file_id);
  967. }
  968. if ($can_read && user_access("restore from backup")) {
  969. $out[] = l(t("restore"), $path . '/list/restorefile/' . $destination_id .'/'. $file_id);
  970. }
  971. if ($can_delete && user_access("delete backup files")) {
  972. $out[] = l(t("delete"), $path . '/list/deletefile/' . $destination_id .'/'. $file_id);
  973. }
  974. return $out;
  975. }
  976. /**
  977. * Determine if we can read the given file.
  978. */
  979. function can_read_file($file_id) {
  980. return $this->op('restore');
  981. }
  982. /**
  983. * Determine if we can read the given file.
  984. */
  985. function can_delete_file($file_id) {
  986. return $this->op('delete');
  987. }
  988. /**
  989. * Get the form for the settings for this destination type.
  990. */
  991. function settings_default() {
  992. return array();
  993. }
  994. /**
  995. * Get the form for the settings for this destination.
  996. */
  997. function settings_form($form) {
  998. return $form;
  999. }
  1000. /**
  1001. * Validate the form for the settings for this destination.
  1002. */
  1003. function settings_form_validate($form_values) {
  1004. }
  1005. /**
  1006. * Submit the settings form. Any values returned will be saved.
  1007. */
  1008. function settings_form_submit($form_values) {
  1009. return $form_values;
  1010. }
  1011. /**
  1012. * Check that a destination is valid.
  1013. */
  1014. function confirm_destination() {
  1015. return true;
  1016. }
  1017. /**
  1018. * Add the menu items specific to the destination type.
  1019. */
  1020. function get_menu_items() {
  1021. $items = parent::get_menu_items();
  1022. $path = $this->get_settings_path();
  1023. $items[$path . '/list/files'] = array(
  1024. 'title' => 'Destination Files',
  1025. 'page callback' => 'backup_migrate_menu_callback',
  1026. 'page arguments' => array('destinations', 'backup_migrate_ui_destination_display_files', TRUE),
  1027. 'access arguments' => array('access backup files'),
  1028. 'type' => MENU_LOCAL_TASK,
  1029. );
  1030. $items[$path . '/list/deletefile'] = array(
  1031. 'title' => 'Delete File',
  1032. 'description' => 'Delete a backup file',
  1033. 'page callback' => 'backup_migrate_menu_callback',
  1034. 'page arguments' => array('destinations', 'backup_migrate_ui_destination_delete_file', TRUE),
  1035. 'access arguments' => array('delete backup files'),
  1036. 'type' => MENU_LOCAL_TASK,
  1037. );
  1038. $items[$path . '/list/restorefile'] = array(
  1039. 'title' => 'Restore from backup',
  1040. 'description' => 'Restore database from a backup file on the server',
  1041. 'page callback' => 'backup_migrate_menu_callback',
  1042. 'page arguments' => array('destinations', 'backup_migrate_ui_destination_restore_file', TRUE),
  1043. 'access arguments' => array('restore from backup'),
  1044. 'type' => MENU_LOCAL_TASK,
  1045. );
  1046. $items[$path . '/downloadfile'] = array(
  1047. 'title' => 'Download File',
  1048. 'description' => 'Download a backup file',
  1049. 'page callback' => 'backup_migrate_menu_callback',
  1050. 'page arguments' => array('destinations', 'backup_migrate_ui_destination_download_file', TRUE),
  1051. 'access arguments' => array('access backup files'),
  1052. 'type' => MENU_CALLBACK,
  1053. );
  1054. return $items;
  1055. }
  1056. }
  1057. /**
  1058. * A base class for creating destinations.
  1059. */
  1060. class backup_migrate_destination_remote extends backup_migrate_destination {
  1061. /**
  1062. * The location is a URI so parse it and store the parts.
  1063. */
  1064. function get_location() {
  1065. return $this->url(FALSE);
  1066. }
  1067. /**
  1068. * The location to display is the url without the password.
  1069. */
  1070. function get_display_location() {
  1071. return $this->url(TRUE);
  1072. }
  1073. /**
  1074. * Return the location with the password.
  1075. */
  1076. function set_location($location) {
  1077. $this->location = $location;
  1078. $this->set_url($location);
  1079. }
  1080. /**
  1081. * Destination configuration callback.
  1082. */
  1083. function edit_form() {
  1084. $form = parent::edit_form();
  1085. $form['scheme'] = array(
  1086. "#type" => "textfield",
  1087. "#title" => t("Scheme"),
  1088. "#default_value" => @$this->dest_url['scheme'] ? $this->dest_url['scheme'] : '',
  1089. "#required" => TRUE,
  1090. "#weight" => 0,
  1091. );
  1092. $form['host'] = array(
  1093. "#type" => "textfield",
  1094. "#title" => t("Host"),
  1095. "#default_value" => @$this->dest_url['host'] ? $this->dest_url['host'] : 'localhost',
  1096. "#required" => TRUE,
  1097. "#weight" => 10,
  1098. );
  1099. $form['path'] = array(
  1100. "#type" => "textfield",
  1101. "#title" => t("Path"),
  1102. "#default_value" => @$this->dest_url['path'],
  1103. "#required" => TRUE,
  1104. "#weight" => 20,
  1105. );
  1106. $form['user'] = array(
  1107. "#type" => "textfield",
  1108. "#title" => t("Username"),
  1109. "#default_value" => @$this->dest_url['user'],
  1110. "#required" => TRUE,
  1111. "#weight" => 30,
  1112. );
  1113. $form['pass'] = array(
  1114. "#type" => "password",
  1115. "#title" => t("Password"),
  1116. "#default_value" => @$this->dest_url['pass'],
  1117. '#description' => '',
  1118. "#weight" => 40,
  1119. );
  1120. if (@$this->dest_url['pass']) {
  1121. $form['old_password'] = array(
  1122. "#type" => "value",
  1123. "#value" => @$this->dest_url['pass'],
  1124. );
  1125. $form['pass']["#description"] .= t(' You do not need to enter a password unless you wish to change the currently saved password.');
  1126. }
  1127. return $form;
  1128. }
  1129. /**
  1130. * Submit the configuration form. Glue the url together and add the old password back if a new one was not specified.
  1131. */
  1132. function edit_form_submit($form, &$form_state) {
  1133. $form_state['values']['pass'] = $form_state['values']['pass'] ? $form_state['values']['pass'] : $form_state['values']['old_password'];
  1134. $form_state['values']['location'] = $this->glue_url($form_state['values'], FALSE);
  1135. parent::edit_form_submit($form, $form_state);
  1136. }
  1137. }