function addNewRelease() { $release = Release::create(array('strReleasesID' => Input::get('releaseID'), 'strReleaseBrchID' => Input::get('branchID'), 'strReleaseBy' => Input::get('empID'), 'dtDateReleased' => date('Y-m-d'))); $release->save(); $ids = DB::table('tblReleaseNotes')->select('strReleaseNotesID')->orderBy('updated_at', 'desc')->orderBy('strReleaseNotesID', 'desc')->take(1)->get(); $ID = $ids["0"]->strReleaseNotesID; $newID = $this->smart($ID); $notes = ReleaseNote::create(array('strReleaseNotesID' => $newID, 'strReleaseID' => Input::get('releaseID'), 'strReleaseNotesStat' => 'Pending')); $notes->save(); $item = Input::get('itemsRelease'); // 'strOPOrdersID', 'strOPProdID', 'intOPQuantity' for ($i = 0; $i < count($item); $i++) { $relItem = ReleaseDetail::create(array('strReleaseHeaderID' => Input::get('releaseID'), 'strReleaseProducts' => $item[$i][1], 'intReleaseQty' => $item[$i][3])); $relItem->save(); } $prod = Input::get('itemsRelease'); for ($ctr = 0; $ctr < count($prod); $ctr++) { $qty = $prod[$ctr][3]; //$prodID = $prod[$ctr][1]; // $batch = DB::table('tblInventory') // ->select('strBatchID') // ->where('strProdID','=',$prodID) // ->orderBy('strBatchID', 'asc') // ->take(1) // ->get(); $batch = $prod[$ctr][0]; //$inv = $batch["0"]->strBatchID; $inventory = Inventory::find($batch); $inventory->intAvailQty -= $qty; $inventory->save(); } }
public function deploy($force, $keep) { try { // // 1. Make sure the target directory does not exist (or exists and is empty) // 2. Load or create the releases manifest // 3. Deploy the app into the releases directory // 4. Validate the deploy // 5. Create or update the "current" symlink // // // Make sure the environment is sane // // Got all the deploy directories? $this->check_and_create_dir($this->deploy_dir); $this->check_and_create_dir($this->releases_dir); $this->check_and_create_dir($this->shared_dir); // // Load up the manifest and create the new release // $this->load_releases_manifest(); // TODO: add support for a release message if (count($this->releases_manifest)) { $release_number = $this->releases_manifest[count($this->releases_manifest) - 1]->number + 1; } else { $release_number = 0; } $new_release = new Release($this->releases_dir, '', $release_number); // Make it. $new_release->create($force); // // Did everything work? // $checks = ['wp-login.php is missing; is WordPress properly deployed?' => !file_exists("{$new_release->release_dir}/wp-login.php"), 'wp-includes/wp-db.php is missing; is WordPress properly deployed?' => !file_exists("{$new_release->release_dir}/wp-includes/wp-db.php"), 'wp-admin/edit.php is missing; is WordPress properly deployed?' => !file_exists("{$new_release->release_dir}/wp-admin/edit.php"), 'wp-content/themes is missing; is the app properly deployed?' => !file_exists("{$new_release->release_dir}/wp-content/themes"), 'wp-content/plugins is missing; is the app properly deployed?' => !file_exists("{$new_release->release_dir}/wp-content/plugins"), 'wp-config.php is not in the shared directory.' => !file_exists("{$new_release->release_dir}/../../shared/wp-config.php"), 'uploads directory is not in the shared directory.' => !file_exists("{$new_release->release_dir}/../../shared/uploads") && !is_link("{$new_release->release_dir}/../../shared/uploads"), "wp-config.php doesn't contain DB_NAME; is it valid?" => !strpos(file_get_contents("{$new_release->release_dir}/../../shared/wp-config.php"), 'DB_NAME'), 'wp-config.php is missing; did the symlinking fail?' => !file_exists("{$new_release->release_dir}/wp-config.php"), 'wp-content/uploads is missing; did the symlinking fail?' => !file_exists("{$new_release->release_dir}/wp-content/uploads") && !is_link("{$new_release->release_dir}/../../shared/uploads")]; $release_ok = true; $messages = []; foreach ($checks as $message => $failed) { if ($failed) { $release_ok = false; $messages[] = "\t{$message}"; } } // // If it was all ok: // if (!$release_ok) { $broken_release = $broken_release_prefix = "{$new_release->release_dir}.broken"; $count = 1; while (file_exists($broken_release)) { $broken_release = $broken_release_prefix . "_{$count}"; ++$count; } rename("{$new_release->release_dir}", "{$broken_release}"); echo "Problems:\n"; echo implode($messages, "\n"); echo "\n\nRelease did not validate; it has been moved to: {$broken_release}"; exit(1); } else { // If we are forcing, rejig some directories if ($force) { rename("{$this->releases_dir}/{$new_release->deployed_commit}", "{$this->releases_dir}/{$new_release->deployed_commit}_" . ($new_release->number - 1)); rename("{$new_release->release_dir}", "{$this->releases_dir}/{$new_release->deployed_commit}"); $new_release->release_dir = "{$this->releases_dir}/{$new_release->deployed_commit}"; } $current = "{$new_release->release_dir}/../../current"; // If we are not forcing, check to see if the release being deployed is the currently deployed release - if so, do nothing if (!$force && file_exists($current) && readlink($current) == realpath($new_release->release_dir)) { return; } if (file_exists($current)) { unlink("{$current}"); } symlink(realpath("{$new_release->release_dir}"), "{$current}"); // Update manifest $release = new \stdClass(); $release->time = $new_release->time; $release->number = $new_release->number; $release->deployed_commit = $new_release->deployed_commit; $this->releases_manifest[] = $release; $this->save_releases_manifest(); } } catch (Exception $e) { echo $e->getMessage(); exit(1); } // // Delete old deploys // // This is a bit hacky. I would like to use the data from the releases manifest for this, but the moving around // of directories on -f kinda screws that up. It needs to be made better, and then we can do this properly. // $releases = glob(realpath("{$this->releases_dir}") . '/*', GLOB_ONLYDIR); uasort($releases, function ($a, $b) { return filemtime($b) - filemtime($a); }); foreach (array_slice($releases, $keep) as $dir) { $this->recurse_rmdir($dir); } }